tag and class ws class only selector

JavaScript performance comparison

Revision 2 of this test case created by Phil Webb

Info

To find all elements with specified class, jQuery needs to fetch them all and then filter it by class name. Specifying tag should limit number of elements selected.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="a">me</div>
<div class="a">me</div>
<div class="a">me</div>
<div>me</div>
<div>me</div>
<span>me</span>
<span>me</span>
<div>me</div>
<div>me</div>
<span>me</span>
<span>me</span>
<div>me</div>
<div>me</div>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<span>me</span>
<script>
Benchmark.prototype.setup = function() {
    var els;
};
</script>

Preparation code output

me
me
me
me
me
me me
me
me
me me
me
me
me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Specifying tag
els = $('div.a');
pending…
Without tag
els = $('.a');
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