Raw Data Selector Performance

JavaScript performance comparison

Revision 37 of this test case created by Mihai Parparita

Preparation code

<ul id="test"></ul>
<script>
Benchmark.prototype.setup = function() {
    var ul = document.querySelector("#test");
    for (var i = 0; i < 1000; i++) {
      var li = document.createElement("li");
      li.textContent = "List Item " + i;
      if (i % 2) {
        li.setAttribute("data-component", "list-item");
        li.className = "list-item my-other-class";
      }
      ul.appendChild(li);
    }
};

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
    data selector
    document.querySelectorAll("[data-component=\"list-item\"]")
    pending…
    class selector
    document.querySelectorAll(".list-item")
    pending…
    two classes
    document.querySelectorAll(".list-item.my-other-class")
    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