Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Doing foreach right way vs fancy hyped way
Show how those hyped array functions perform. Use array functions! But only where it should be used.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Safari/605.1.15
Browser:
Safari 18
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
6 months ago
Benchmark engine:
Benchmark.js
forEach - block
1.8M/s
for..of loop
1.7M/s
forEach - return
1.5M/s
map
853K/s
filter
444K/s
View exact numbers
Test name
Executions per second
✓
forEach - block
1,840,150 Ops/sec
for..of loop
1,661,472 Ops/sec
forEach - return
1,511,896 Ops/sec
map
853,134 Ops/sec
filter
444,432 Ops/sec
Script Preparation code:
var arr = new Array(1000).fill(0);
Tests:
for..of loop
let count = 0; for (const item of arr) { count++; }
forEach - block
let count = 0; arr.forEach(() => { count++; });
forEach - return
let count = 0; arr.forEach(() => count++);
map
let count = 0; arr.map(() => count++);
filter
let count = 0; arr.filter(() => count++);