Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created March 6, 2012 23:22
Show Gist options
  • Save sindresorhus/1989724 to your computer and use it in GitHub Desktop.
Save sindresorhus/1989724 to your computer and use it in GitHub Desktop.
TreeWalker performance

Test the performance of TreeWalker compared to other DOM walker methods. Ran each test 1000 times. Try it yourself.

Chrome 17

Method                  Total ms    Average ms
document.TreeWalker     911         0.911
Iterative Traverser     2945        2.945
Recursive Traverser     69521       69.521
XPath query             4996        4.996
querySelectorAll        12860       12.86
getElementsByTagName    1929        1.929

Safari 5

Method                  Total ms    Average ms
document.TreeWalker     597         0.597
Iterative Traverser     1287        1.287
Recursive Traverser     10542       10.542
XPath query             2995        2.995
querySelectorAll        2769        2.769
getElementsByTagName    311         0.311

Firefox 10

Method                  Total ms    Average ms
document.TreeWalker     6404        6.404
Iterative Traverser     3706        3.706
Recursive Traverser     8838        8.838
XPath query             21041       21.041
querySelectorAll        2815        2.815
getElementsByTagName    182         0.182
@jayarjo
Copy link

jayarjo commented Dec 29, 2019

That page doesn't exist. :'/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment