jQuery Selector

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<ul id="stuff">
                <li rel="fuzzy">cats</li>
                <li rel="hairy">dogs</li>
                <li rel="big">moose</li>
                <li rel="feathers">chicken</li>
                <li rel="gobblegobble">turkey</li>
                <li rel="blahbleep">blah</li>
                <li rel="blubbloop">blub</li>
                <li rel="fuzzy2">cats2</li>
                <li rel="hairy2">dogs2</li>
                <li rel="big2">moose2</li>
                <li rel="feathers2">chicken2</li>
                <li rel="gobblegobble2">turkey2</li>
                <li rel="blahbleep2">blah2</li>
                <li rel="blubbloop2">blub2</li>
                <li rel="fuzzy3">cats3</li>
                <li rel="hairy3">dogs3</li>
                <li rel="big3">moose3</li>
                <li rel="feathers3">chicken3</li>
                <li rel="gobblegobble3">turkey3</li>
                <li rel="blahbleep3">blah3</li>
                <li rel="blubbloop3">blub3</li>
                <li rel="fuzzy4">cats4</li>
                <li rel="hairy4">dogs4</li>
                <li rel="big4">moose4</li>
                <li rel="feathers4">chicken4</li>
                <li rel="gobblegobble4">turkey4</li>
                <li rel="blahbleep4">blah4</li>
                <li rel="blubbloop4">blub4</li>
        </ul>
<script>
Benchmark.prototype.setup = function() {
    var e;
    var rel;
};
</script>

Preparation code output

  • cats
  • dogs
  • moose
  • chicken
  • turkey
  • blah
  • blub
  • cats2
  • dogs2
  • moose2
  • chicken2
  • turkey2
  • blah2
  • blub2
  • cats3
  • dogs3
  • moose3
  • chicken3
  • turkey3
  • blah3
  • blub3
  • cats4
  • dogs4
  • moose4
  • chicken4
  • turkey4
  • blah4
  • blub4

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Children
e = $('#stuff').children('li');
rel = e[e.length-2].getAttribute('rel');
pending…
Find
e = $('#stuff').find('li');
rel = e[e.length-2].getAttribute('rel');
pending…
jQuery 4
e = $('#stuff').children();
rel = e[e.length-2].getAttribute('rel');
pending…
No jQuery Children
e = document.getElementById('stuff').children;
rel = e[e.length-2].getAttribute('rel');
pending…
No jQuery
e = document.getElementById('stuff').getElementsByTagName('li');
rel = e[e.length-2].getAttribute('rel');
pending…
hybrid
e = $(document.getElementById('stuff')).children();
rel = e[e.length-2].getAttribute('rel');
pending…
hybrid 2
e = $(document.getElementById('stuff'))[0].children;
rel = e[e.length-2].getAttribute('rel');
pending…
hybrid3
// async test
e = $(document.getElementById('stuff'))[0].getElementsByTagName('li');
rel = e[e.length-2].getAttribute('rel');
 
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