jQuery Attribute selector performance

JavaScript performance comparison

Revision 12 of this test case created

Info

Test to see if jQuery filters by selector before doing attribute matching.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="x" id="container">
<b class="t" name="test0" id="id_test0"><span class="u" id="span0">a</span></b>
<b class="t" name="test0" id="id_test1"><span class="u" id="span1">a</span></b>
<b class="t" name="test0" id="id_test2"><span class="u" id="span2">a</span></b>
<b class="t" name="test1" id="id_test3"><span class="u" id="span3">a</span></b>
<b class="t" name="test1" id="id_test4"><span class="u" id="span4">a</span></b>
<b class="t" name="test1" id="id_test5"><span class="u" id="span5">a</span></b>
</div>

Preparation code output

a a a a a a

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
tag+attr id
$('b[id="id_test3"]');
pending…
byid
$("#id_test3");
pending…
name
$('b#id_test3');
pending…
$('#id_test3 #span3');
pending…
$('#span3');
pending…
$('#id_test3 u');
pending…
$('#container').find('[name$=test1]')
pending…
$('#container').find('[name=test1]')
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