Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
findIndex vs IndexOf + map vs binary search
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 138
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Binary search
9.3M/s
findIndex
38K/s
Map + IndexOf
4K/s
View exact numbers
Test name
Executions per second
✓
Binary search
9,317,477 Ops/sec
findIndex
38,301 Ops/sec
Map + IndexOf
3,800 Ops/sec
HTML Preparation code:
<script> function binarySearch(lst, x) { var left = 0; var right = lst.length - 1; while (left <= right) { var mid = Math.floor((left + right) / 2); if (lst[mid] === x) { return mid; } if (lst[mid] < x) { left = mid + 1; } else { right = mid - 1; } } return -1; } </script>
Script Preparation code:
var arr = new Array(15000); arr.fill({ id: 0 }); arr = arr.map((el, idx) => el.id = idx); var foo = Math.floor(Math.random() * 15000);
Tests:
findIndex
arr.findIndex(x => x.id ===foo );
Map + IndexOf
arr.map(x => x.id).indexOf(foo);
Binary search
binarySearch(arr,foo)