loop-vs-treewalker (v2)

Revision 2 of this benchmark created on


Preparation HTML

<section>
<div>

<ul>
<li>1</li>
<li>2</li>
<li id="start">3</li>
</ul>

</div>

</section>

Setup

var start = document.getElementById('start');
    
    var walker = document.createTreeWalker(document, 1, {
      acceptNode: function(node){
        return node.nodeName = 'SECTION';
      }
    }, false);

Test runner

Ready to run.

Testing in
TestOps/sec
loop
var node = start, found;

while(node.parentNode) {
  if (node.nodeName == 'SECTION') {
    return found = node;
  }
  node = node.parentNode;
}
ready
walker
walker.currentNode = start;
walker.parentNode();
ready

Revisions

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