Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
NodeList For vs Foreach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
forEach
5.8M/s
Default For
3K/s
For with length caching
2K/s
View exact numbers
Test name
Executions per second
✓
forEach
5,767,589 Ops/sec
Default For
3,380 Ops/sec
For with length caching
2,192 Ops/sec
Script Preparation code:
var div = document.createElement('div'); for (let i = 0; i < 1000; i++) { div.insertAdjacentHTML('beforeend', `<span>span-${i}<span>`); } var list = div.querySelectorAll('span');
Tests:
Default For
for(let i = 0; i < list.length; i++) { list[i].setAttribute('tabindex', '-1'); }
For with length caching
list.forEach(item =>{ item.setAttribute('tabindex', '-1'); });
forEach
for(let i = 0, lenght = list.lenght ; i < length; i++) { list[i].setAttribute('tabindex', '-1'); }