Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
medium set vs binary search
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser:
Firefox 146
Operating system:
Linux
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
array
9928969.0 Ops/sec
set
360007520.0 Ops/sec
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);