Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test create object: forEach vs map vs for in vs for of vs reduce
(version: 4)
Comparing performance of:
forEach vs map vs for of vs for in vs reduce
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 1000000; ++i) { result.push(i); } return result; } var array = generateTestArray()
Tests:
forEach
var store = {}; array.forEach((elm) => { store[elm] = true; });
map
var store2 = {}; array.map((elm) => { store2[elm] = true; });
for of
var store3 = {}; for(const elm of array){ store3[elm] = true; }
for in
var store4 = {}; for(const index in array){ store4[array[index]] = true; }
reduce
array.reduce((acc, curr) => ({...acc,[curr]: true }), {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
forEach
map
for of
for in
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?