Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Binary search in sorted 100k int array
(version: 0)
Comparing performance of:
Includes vs binary vs Set.has()
Created:
one year ago
by:
Guest
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Includes
binary
Set.has()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Includes
45789.2 Ops/sec
binary
9799881.0 Ops/sec
Set.has()
15361554.0 Ops/sec
Related benchmarks:
Count sort vs JS native sort
javascript count sort vs native sort
Javascript Sorting Algorithms mdhe
LinearSearch vs BinarySearch
Comments
Confirm delete:
Do you really want to delete benchmark?