Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.map vs for loop vs for loop cached vs for of
(version: 1)
Comparing performance of:
.map vs for loop vs for loop cached vs for of
Created:
11 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
// Create sample data var array = [1,2,3,4,5,6,7,8,9,0]; var manipulateFn = num => { return num * 2 * 3; }
Tests:
.map
var newArray = array.map( i => manipulateFn(i));
for loop
var newArray = []; for (let i=0; i<array.length; i++) { newArray.push(manipulateFn(array[i])); }
for loop cached
var newArray = []; const arrayLength = array.length; for (let i=0; i<arrayLength; i++) { newArray.push(manipulateFn(array[i])); }
for of
var newArray = []; for (let value of array) { newArray.push(manipulateFn(value)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
.map
for loop
for loop cached
for of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser/OS:
Firefox 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.map
12893403.0 Ops/sec
for loop
30993012.0 Ops/sec
for loop cached
28764968.0 Ops/sec
for of
10773080.0 Ops/sec
Related benchmarks:
For Each Vs Map Example Medium 2
comparing for vs map vs forEach methods
for loop vs. .map
for loop vs. .map [2]
for loop vs. .map but fast
for loop vs. .map anon
for loop vs. .map with size
for loop vs. .map 100k
.map vs for loop
Comments
Confirm delete:
Do you really want to delete benchmark?