Attribute versus class querying

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<div>
  <div class="alpha">
    .alpha
  </div>
  <div class="alpha" data-bravo>
    .alpha[bravo]
  </div>
  <div class="alpha" data-bravo="charlie">
    .alpha[bravo="charlie"]
    <div class="alpha">
      .alpha
    </div>
    <div data-bravo>
      [bravo]
    </div>
    <div data-bravo="charlie">
      [bravo="charlie"]
    </div>
  </div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Preparation code output

.alpha
.alpha[bravo]
.alpha[bravo="charlie"]
.alpha
[bravo]
[bravo="charlie"]

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
qsa class
var a = document.querySelectorAll('.alpha');
pending…
jQuery class
var b = $('div.alpha');
pending…
qsa attr
var c = document.querySelectorAll('[data-bravo]');
pending…
jQuery attr
var d = $('[data-bravo]');
pending…
qsa attr=value
var e = document.querySelectorAll('[data-bravo="charlie"]');
pending…
jQuery attr=value
var f = $('[data-bravo="charlie"]');
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