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; rv:144.0) Gecko/20100101 Firefox/144.0
Browser:
Firefox 144
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
Array.indexOf
7091876.0 Ops/sec
Map.get
20703182.0 Ops/sec
Array.findIndex
8372764.5 Ops/sec
Array.indexOf Object
7513426.0 Ops/sec
Map.get Object
20961688.0 Ops/sec
Array.findIndex Object
3970407.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); });