jQuery objects comparison

JavaScript performance comparison

Test case created by Mathieu Parent

Info

Different ways of testing if a jQuery object is the same as another.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id=1>
</div>
<div id=2>
</div>
<div id=3>
</div>
<script>
Benchmark.prototype.setup = function() {
    var $div1 = $("#1");
    var $div2 = $("#2");
    var $div3 = $("#1");
    var test;
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Raw DOM elements
test = $div1.get(0) == $div3.get(0);
pending…
Raw DOM elements 2
test = $div1[0] == $div3[0];
pending…
jQuery.is()
test = $div1.parent().is($div3)
pending…
Test on childs
test = ($div1.length == $div3.length && $div1.length == $div3.filter($div1).length);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment