Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Duplicate to unique array time complexity measure w/ different approaches.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15
Browser:
Safari 15
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Solution w/ Array methods
18.5 Ops/sec
Solution w/ Map
220.2 Ops/sec
Solution w/ Set
239.7 Ops/sec
Script Preparation code:
function initArr(size) { const array = []; for (let i = 0; i < size; i++) { array.push(Math.floor(Math.random() * size)); } return array; }
Tests:
Solution w/ Array methods
const arr = initArr(10000); const uniqueArray = []; arr.forEach(item => { if (!uniqueArray.includes(item)) { uniqueArray.push(item); } });
Solution w/ Map
const arr = initArr(10000); const map = new Map(); const uniqueArray = arr.map(item => { if (!map.has(item)) { map.set(item, true); return item } });
Solution w/ Set
const arr = initArr(10000); const uniqueArray = Array.from(new Set(arr));