Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Index an element in array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser:
Chrome 143
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
Array.indexOf
14068353.0 Ops/sec
Map.get
48334256.0 Ops/sec
Array.findIndex
22477300.0 Ops/sec
Array.indexOf Object
21452514.0 Ops/sec
Map.get Object
89910304.0 Ops/sec
Array.findIndex Object
28675804.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here--> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
const array = Array.from({ length: 10 }, () => Math.random()); const arrayObject = Array.from({ length: 10 }, () => ({ value: Math.random() })); const map = new Map(); const mapObject = new Map(); array.forEach((v, i) => map.set(v, i)); arrayObject.forEach((v, i) => map.set(v, i)); const testArray = _.shuffle(array); const testArrayObject = _.shuffle(arrayObject);
Tests:
Array.indexOf
testArray.forEach(v => { const index = array.indexOf(v); });
Map.get
testArray.forEach(v => { const index = map.get(v) ?? -1; });
Array.findIndex
testArray.forEach(v => { const index = array.findIndex(vv => v === vv); });
Array.indexOf Object
testArrayObject.forEach(v => { const index = arrayObject.indexOf(v); });
Map.get Object
testArrayObject.forEach(v => { const index = mapObject.get(v) ?? -1; });
Array.findIndex Object
testArrayObject.forEach(v => { const index = arrayObject.findIndex(vv => v === vv); });