jQuery selectors

JavaScript performance comparison

Revision 3 of this test case created by LesTR

Info

Testing speed of different selectors.

Preparation code

<div class="test"></div>
<div id="test1" class="test"></div>
<a href="#">test</a>
<a class="test">test</a>
<input type="text"/>
<input type="text"/>
<textarea></textarea>
<button>test</button>
<select></select>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"></script>

Preparation code output

test test

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery-Tag-ID
jQuery('div#test1')
pending…
jQuery-ID
jQuery('#test1')
pending…
jQuery-Tag-class
jQuery('div.test')
pending…
jQuery-Class
jQuery('.test')
pending…
jQuery-Tag
jQuery('div')
pending…
jQuery-Attr with tag
jQuery('a[href=#]')
pending…
jQuery-Attr
jQuery('[href=#]')
pending…
jQuery-Attr alone
jQuery('[href]')
pending…
jQuery-Filter with tag
jQuery('input:text')
pending…
jQuery-Filter
jQuery(':text')
pending…
jQuery-:input filter
jQuery(':input')
pending…
jQuery-tags same as :input filter
jQuery('input, select, button, textarea')
pending…
Dojo-Tag-ID
dojo.query('div#test1')
pending…
Dojo-ID
dojo.query('#test1')
pending…
Dojo-Tag-class
dojo.query('div.test')
pending…
Dojo-Class
dojo.query('.test')
pending…
Dojo-Tag
dojo.query('div')
pending…
Dojo-Attr with tag
dojo.query('a[href=#]')
pending…
dojo-Attr alone
dojo.query('[href]')
pending…
Dojo-Filter with tag
dojo.query('input[type="text"]')
pending…
Dojo-tags same as :input filter
dojo.query('input, select, button, textarea')
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