Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Make array of primitives unique
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Array.findIndex
80.4 Ops/sec
Array.indexOf
117.7 Ops/sec
Array.from(new Set(array))
4068.0 Ops/sec
Object-filter
9752.6 Ops/sec
Object-values
10600.6 Ops/sec
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * max); } var arr = []; for(let i = 0; i < 10000; i++) { arr.push(getRandomInt(1000)); }
Tests:
Array.findIndex
const compare = (a,b) => a === b; arr.filter((item, idx) => arr.findIndex(compare) === idx);
Array.indexOf
arr.filter((item, idx) => arr.indexOf(item) === idx);
Array.from(new Set(array))
Array.from(new Set(arr));
Object-filter
const obj = {}; arr.filter((item) => { if(!obj[item]){ obj[item] = true; return true; } return false; });
Object-values
Object.values(arr.reduce((acc, item) => { if(!acc[item]){ acc[item] = item; } return acc; }, {}));