Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
.map vs for loop vs for loop cached vs for of
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser:
Firefox 139
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
for loop
31.0M/s
for loop cached
28.8M/s
.map
12.9M/s
for of
10.8M/s
View exact numbers
Test name
Executions per second
✓
for loop
30,993,012 Ops/sec
for loop cached
28,764,968 Ops/sec
.map
12,893,403 Ops/sec
for of
10,773,080 Ops/sec
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)); }