Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Binary search in sorted 100k int array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Includes
31139.2 Ops/sec
binary
4668111.0 Ops/sec
Set.has()
7131533.0 Ops/sec
Script Preparation code:
var set = new Set(); let max = 200000; let min = 0; while (set.size <= 100000){ let n = Math.floor(Math.random() * (max - min + 1)) + min; set.add(n); } var array = Array.from(set); array.sort((a, b) => a - b); var num = array[29204]; function binarySearch(arr, x) { let min = 0; let max = arr.length - 1; let index = 0; let val; while (min <= max) { index = (min + max) >> 1; val = arr[index]; if (x < val) { max = index - 1; } else if (x > val) { min = index + 1; } else { return index; } } return -1; }
Tests:
Includes
array.includes(num)
binary
binarySearch(array, num)
Set.has()
set.has(num);