Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
findIndex vs IndexOf + map vs binary search
(version: 1)
Comparing performance of:
findIndex vs Map + IndexOf vs Binary search
Created:
one year ago
by:
Guest
Go to the latest result
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)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
findIndex
Map + IndexOf
Binary search
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Binary search
19.5M/s
findIndex
27K/s
Map + IndexOf
12K/s
View exact numbers
Test name
Executions per second
✓
Binary search
19,531,486 Ops/sec
findIndex
27,175 Ops/sec
Map + IndexOf
11,858 Ops/sec
Related benchmarks
Include vs Binary search in sorted array vs Map.has() vs Object[]
Include vs Binary search in sorted array vs Map.has() vs Object[] (100 elements)
Include vs Binary search in sorted array vs Map.has() vs Object[] large ver.
Binary search in sorted 100k int array
Comments
Confirm delete:
Do you really want to delete benchmark?