Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs for ... of vs forEach vs map
(version: 1)
Compare loop performance
Comparing performance of:
for vs for ... of vs forEach vs map
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const array = Array.from({ length: 100 }, (_, i) => i) const result = []
Tests:
for
const result = [] for (let i = 0; i < array.length; i++) { result.push(array[i] * 2) }
for ... of
const result = [] for (const value of array) { result.push(value * 2) }
forEach
const result = [] array.forEach((value) => { result.push(value * 2) })
map
const result = array.map((value) => value * 2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for
for ... of
forEach
map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
2224217.8 Ops/sec
for ... of
998806.7 Ops/sec
forEach
1781016.0 Ops/sec
map
1731814.1 Ops/sec
Related benchmarks:
for vs foreach vs map vs for..of
for vs foreach vs some vs for..of (that really works) 2
for loops and stuff
for vs foreach vs for..of vs for..of over entries (const)
For vs for of vs forEach
for vs foreach vs some vs for..of fixed
for vs foreach vs for..of vs for..of over entries (const) etc
for vs foreach vs for-const vs for..of
Array.from vs map 1
Comments
Confirm delete:
Do you really want to delete benchmark?