Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
find faster - for vs find vs map vs foreach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Ubuntu
Device Platform:
Desktop
Date tested:
one year ago
for
1.1M/s
prototype.find
259K/s
forEach
11K/s
map
10K/s
View exact numbers
Test name
Executions per second
✓
for
1,108,073 Ops/sec
prototype.find
259,477 Ops/sec
forEach
10,664 Ops/sec
map
9,902 Ops/sec
Script Preparation code:
var arr = [] let i = 0 let len = 1000 for(;i<len;i++) { arr.push(i) }
Tests:
for
let i = 0 let len = arr.length let foundIndex = -1 for(;i<len;i++) { if (arr[i] > 999){ return i } }
prototype.find
const found = arr.find(function(element) { return element > 999 })
forEach
let foundForEachIndex = -1 arr.forEach(function (item){ if (item[i] > 999){ foundForEachIndex = i return } })
map
let foundMapIndex = arr.map(item => { if (item[i] > 999){ return i } })