Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
TreeWalker/ filter vs querySelectorAll vs NodeIterator /filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 133
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Benchmark engine:
Benchmark.js
querySelectorAll
300K/s
TreeWalker
62K/s
NodeIterator
56K/s
View exact numbers
Test name
Executions per second
✓
querySelectorAll
299,534 Ops/sec
TreeWalker
62,374 Ops/sec
NodeIterator
55,616 Ops/sec
HTML Preparation code:
<!-- article out start --> <article> <!-- article in start --> <h1>Lorem ipsum</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p> <!-- article in end --> </article> <!-- article out end --> <!-- article out start --> <article> <!-- article in start --> <h1>Lorem ipsum</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p> <!-- article in end --> </article> <!-- article out end --> <!-- article out start --> <article> <!-- article in start --> <h1>Lorem ipsum</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p> <!-- article in end --> </article> <!-- article out end -->
Tests:
TreeWalker
const filter = function(node) { return node.tagName == "H1" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; }; const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_ELEMENT, filter, false ); for (let node = walker.nextNode(), i = 0; node; i++, node= walker.nextNode() ) { node.className = 'classy' ; }
querySelectorAll
const elements = Array.from(document.body.querySelectorAll('h1')) for(let el of elements){el.className = 'classy'}
NodeIterator
const filter = function(node) { return node.tagName == "H1" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; }; const walker = document.createNodeIterator( document.body, NodeFilter.SHOW_ELEMENT, filter, false ); for (let node = walker.nextNode(), i = 0; node; i++, node= walker.nextNode() ) { node.className = 'classy' ; }