Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Search Results Web results Performance of for loops with JavaScript
(version: 3)
Comparing performance of:
reduce vs for loop vs for each vs for of
Created:
6 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var posts = []; for(let i = 0; i < 1000000; i++) { posts.push({ upVotes: i, }); }
Tests:
reduce
let sum = 0; sum = posts.reduce((s, p) => s += p.upVotes, 0);
for loop
let sum = 0; for (let i = 0; i < posts.length; i++) { sum += posts[i].upVotes; }
for each
let sum = 0; posts.forEach(element => { sum += element.upVotes; });
for of
let sum = 0; for(const post of posts) { sum += post.upVotes; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
reduce
for loop
for each
for of
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:
foreach
while vs for
let vs var for loop
forEach vs for len vs for in vs for of loops
Million loops
Comments
Confirm delete:
Do you really want to delete benchmark?