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; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
for
1375661.0 Ops/sec
prototype.find
277257.5 Ops/sec
forEach
15169.1 Ops/sec
map
12106.9 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 } })