Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Find Smallest Number Not In An Array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0
Browser:
Firefox 143
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
Set With For Loop
3516.7 Ops/sec
Sort With For Loop
1933.7 Ops/sec
Sort With Reduce
1620.5 Ops/sec
Script Preparation code:
var array = []; array.length = 10000; array.fill(undefined); array = array.map(() => Math.floor(Math.random() * array.length));
Tests:
Set With For Loop
const set = new Set(array); function findSet() { for (let i = 0; i < array.length; i++) if (!set.has(i)) return i; return -1; } findSet();
Sort With For Loop
const sortedArray = array.slice().sort((a, b) => a - b); function findSort() { for (let i = 0; i < array.length; i++) if (!sortedArray.includes(i)) return i; return -1; } findSort();
Sort With Reduce
const sortedReduceArray = array.slice().sort((a, b) => a - b); function findReduce() { return sortedReduceArray.reduce((acc, current) => (Math.abs(current - acc) > 1 ? Math.min : Math.max)(current, acc), 0) + 1; } findReduce();