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/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser:
Chrome 142
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
Array.indexOf
16115263.0 Ops/sec
Map.get
56974180.0 Ops/sec
Array.findIndex
26013766.0 Ops/sec
Array.indexOf Object
23242304.0 Ops/sec
Map.get Object
82420888.0 Ops/sec
Array.findIndex Object
33346444.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); });