Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array with Objects loop
Loop through an array of objects and change one property
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
Browser:
Firefox 135
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
For
226K/s
For-of
154K/s
Foreach
151K/s
map
117K/s
For-in
13K/s
View exact numbers
Test name
Executions per second
✓
For
225,924 Ops/sec
For-of
154,490 Ops/sec
Foreach
150,789 Ops/sec
map
116,928 Ops/sec
For-in
13,021 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const array = Array.from({ length: 1000 }, function(_v, index) { return { index } } )
Tests:
For
for (let i = 0; i < array.length; i++) { let item = array[i] item.index = i + 1 } console.log('for', array)
Foreach
array.forEach(function(item, i) { item.index = i + 1 }); console.log('forEach', array)
For-in
for (let i in array) { let item = array[i] item.index = i + 1 } console.log('for-in', array)
For-of
let i = 0 for (let item of array) { item.index = i + 1 i++ } console.log('for-of', array)
map
array.map((item,i) => { item.index = i + 1 }) console.log('map', array)