Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
js array comparison - for vs find vs map vs foreach
Comparing performance of: for vs prototype.find vs forEach vs map
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser:
Firefox 140
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
For
142K/s
find
45K/s
map
31K/s
View exact numbers
Test name
Executions per second
✓
For
141,661 Ops/sec
find
44,754 Ops/sec
map
30,622 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var arr = [] let i = 0 let len = 1000 for (; i < len; i++) { arr.push({ ID: i, TestName: "Name" }) }
Tests:
For
let i = 0 let len = arr.length let foundIndex = -1 for (; i < len; i++) { if (arr[i].ID >= 999) { return arr[i] } }
find
const found = arr.find(function(element) { if(element.ID > 999){ return element }})
map
let foundMapIndex = arr.map(item => { if (item.ID > 999){ return i }})