filtered childNodes vs querySelectorAll

Benchmark created by Benjamin De Cock on


Preparation HTML

<div class=testParent>

  <!-- foo -->
  <p>foo</p>

</div>

<div class=testParent>

  <!-- bar -->
  <p>bar</p>

</div>

Test runner

Ready to run.

Testing in
TestOps/sec
filtered childNodes
var testParents = document.getElementsByClassName("testParent"),
    result = []

for (var i=0; i<testParents.length; i++) {
  var nodes = testParents[i].childNodes
  for (var j=0; j<nodes.length; j++)
    if (nodes[j].nodeType == 1) result.push(nodes[j])
}
ready
querySelectorAll
var result = document.querySelectorAll(".testParent > *")
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Benjamin De Cock on