Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
String in Array: Set vs Object lookup vs IndexOf vs includes vs findIndex vs find v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0
Browser:
Firefox 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
indexOf
1328633.4 Ops/sec
includes
1329868.4 Ops/sec
find
1109273.2 Ops/sec
findIndex
1083270.2 Ops/sec
set
1466837.0 Ops/sec
object lookup
4039137.5 Ops/sec
Script Preparation code:
var arr = []; var i = 0; while (i <= 10) arr[i] = ('' + i++); var testSet = new Set(arr); var testObj = {}; for (const a of arr) { testObj[a] = true; } var randomKeys = []; i = 0; while (i <= 50) { randomKeys.push(''+Math.round(Math.random(50000) + 5000)); i++; }
Tests:
indexOf
for (const key of randomKeys) {const index = arr.indexOf(key);}
includes
for (const key of randomKeys) {const index = arr.includes(key);}
find
for (const key of randomKeys) {const index = arr.find(item => item == key);}
findIndex
for (const key of randomKeys) {const index = arr.findIndex(item => item == key);}
set
for (const key of randomKeys) {const index = testSet.has(key);}
object lookup
for (const key of randomKeys) {const index = testObj[key];}