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:124.0) Gecko/20100101 Firefox/124.0
Browser:
Firefox 124
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
for
764832.6 Ops/sec
prototype.find
212687.4 Ops/sec
forEach
10960.0 Ops/sec
map
10436.5 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 } })