Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Default For
1664.2 Ops/sec
For with length caching
1741.4 Ops/sec
forEach
4449068.0 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'); }