Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for-of-vs-map-bad
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/17.6 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
for of
112940.2 Ops/sec
map
127299.7 Ops/sec
bad map
123415.5 Ops/sec
Script Preparation code:
var arr = []; for (var i = 0; i < 1000; i++) { arr[i] = { name: `${i}`, value: i }; } function someFn(i) { const x24 = i.value * 3 * 8; i.value = x24; i.name = `${x24}`; return i; }
Tests:
for of
const x = Array(arr.length) for (var y of arr) { x.push(someFn(y)); }
map
const x = arr.map(item => someFn(item))
bad map
const x = arr.map((i) => { const x24 = i.value * 3 * 8; i.value = x24; i.name = `${x24}`; return i; })