Data Selector Performance

JavaScript performance comparison

Revision 6 of this test case created by Álister

Preparation code

<ul id="test">
</ul>
<script>
Benchmark.prototype.setup = function() {
    var i = 500;
    var ul = document.getElementById("test");
    ul.innerHtml = "";
    while (i > 0) {
      ul.innerHtml += '<li ' + (i % 100 ? 'data-component="list-item" class="list-item my-other-class"' : '') + '>List Item ' + i.toString() + '</li>';
      i -= 1;
    }
};

Benchmark.prototype.teardown = function() {
    ul.innerHtml = ""
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
classSelector
document.querySelectorAll(".list-item")
pending…
dataSelector
document.querySelectorAll('[data-component]')
pending…
dataSelector with value
document.querySelectorAll('[data-component="list-item"]')
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