Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Performance of JavaScript .forEach, for in v3
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser:
Firefox 128
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
.forEach
6/s
for..of destructured
6/s
for..of
6/s
.forEach destructured
6/s
View exact numbers
Test name
Executions per second
✓
.forEach
6 Ops/sec
for..of destructured
6 Ops/sec
for..of
6 Ops/sec
.forEach destructured
6 Ops/sec
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 1000000; ++i) { result.push({ a: i, b: i / 2, r: 0, }); } return result; }
Tests:
.forEach destructured
const array = generateTestArray(); const newMap = new Map(); array.forEach(({a, b}) => { newMap.set(a, b); }); const foo = [...newMap.entries()];
for..of destructured
const array = generateTestArray(); const newMap = new Map(); for(const {a, b} of array) { newMap.set(a, b); } const foo = [...newMap.entries()];
.forEach
const array = generateTestArray(); const newMap = new Map(); array.forEach((x) => { const {a, b} = x; newMap.set(a, b); }); const foo = [...newMap.entries()];
for..of
const array = generateTestArray(); const newMap = new Map(); for(const x of array) { const {a, b} = x; newMap.set(a, b); } const foo = [...newMap.entries()];