Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript ruletz
(version: 0)
Comparing performance of:
for loop vs forEach vs map vs reduce
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
for loop
const items = Array.from({ length: 100000 }, (_, index) => index); for (let i = 0; i < items.length; i++) { const result = items[i] * 2; }
forEach
const items = Array.from({ length: 100000 }, (_, index) => index); items.forEach((item) => { const result = item * 2; });
map
const items = Array.from({ length: 100000 }, (_, index) => index); const results = items.map((item) => { return item * 2; });
reduce
const items = Array.from({ length: 100000 }, (_, index) => index); const results = items.reduce((accumulator, item) => { const result = item * 2; accumulator.push(result); return accumulator; }, []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for loop
forEach
map
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!
Related benchmarks:
Test speed of undefined
lodash isNil vs native js
_.isFunction vs typeof
lodash isNil vs !!
Lodash.js vs Native undefined
Comments
Confirm delete:
Do you really want to delete benchmark?