Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test on data for 2 years in months
(version: 0)
Comparing performance of:
.forEach vs for..of vs .map vs .map (destructuring) vs .for (init array) vs .reduce
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 24; ++i) { result.push({ a: i, b: i / 2, c: i * 2, }); } return result; }
Tests:
.forEach
const array = generateTestArray(); const newArr = [] array.forEach((x) => { newArr.push(x.a % 2 === 0 ? x : {d: x.a, e: x.b, f: x.c}) });
for..of
const array = generateTestArray(); const newArr = [] for(const x of array) { newArr.push(x.a % 2 === 0 ? x : {d: x.a, e: x.b, f: x.c}) }
.map
const array = generateTestArray(); array.map(x => x.a % 2 === 0 ? x : {d: x.a, e: x.b, f: x.c})
.map (destructuring)
const array = generateTestArray(); array.map(({a,b,c}) => a % 2 === 0 ? {a, b, c} : {d: x.a, e: x.b, f: x.c})
.for (init array)
const array = generateTestArray(); const newArr = [] for (let i = 0; i < array.length; ++i) { newArr.push(array[i].a % 2 === 0 ? array[i] : {d: array[i].a, e: array[i].b, f: array[i].c}) }
.reduce
const array = generateTestArray(); array.reduce((p, x) => p.push(x => x.a % 2 === 0 ? x : {d: x.a, e: x.b, f: x.c}), []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
.forEach
for..of
.map
.map (destructuring)
.for (init array)
.reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?