Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
medium set vs binary search
(version: 1)
Comparing performance of:
array vs set
Created:
3 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
function randomString() { return Math.random().toString(36); } const a = []; const LEN = 100; for (let i = 0; i < LEN; i++) { a.push(randomString()); } const b = new Set(a); function binarySearch(sortedArr, target) { let left = 0, right = sortedArr.length - 1; while (left <= right) { const mid = (left + right) >> 1; if (sortedArr[mid] === target) return mid; if (sortedArr[mid] < target) left = mid + 1; else right = mid - 1; } return -1; } const lookups = []; for (let i = 0; i < LEN; i++) { lookups.push(a[i]); lookups.push(randomString()); }
Tests:
array
const pick = lookups[Math.floor(Math.random() * lookups.length)]; binarySearch(a, pick) >= 0;
set
const pick = lookups[Math.floor(Math.random() * lookups.length)]; b.has(pick);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array
set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array
9928969.0 Ops/sec
set
360007520.0 Ops/sec
Related benchmarks:
Include vs Binary search in sorted array vs Map.has()
Include vs Binary search in sorted array vs Map.has() vs Object[]
Include vs Binary search in sorted array vs Map.has() vs Object[] fork
Include vs Binary search in sorted array vs Map.has() vs Object[] (150 elements)
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[] (25 elements)
Include vs Binary search in sorted array vs Map.has() vs Object[] large ver.
Binary search in sorted 100k int array
findIndex vs IndexOf + map vs binary search
Comments
Confirm delete:
Do you really want to delete benchmark?