test

Benchmark created on


Setup

function getRandomNumber(max, min) {
    max = max ?? Number.MAX_VALUE;
    min = min ?? 0;
    return min + Math.round(Math.random() * (max - min));
}
const data = Array(10000).fill(0).map(p => getRandomNumber());

Test runner

Ready to run.

Testing in
TestOps/sec
set
const set = new Set();
for (let i = 0; i < data.length; i++) {
	set.add(data[0]);
}
const uniqArray = Array.from(set);
ready
array -> set
const data2 = [];
for (let i = 0; i < data.length; i++) {
	data2.push(data[i]);
}
const uniqArray = Array.from(new Set(data2));
ready
object
const data2 = {};
for (let i = 0; i < data.length; i++) {
	data2[data[i]] = true;
}
const arr = Object.keys(data2);
ready
map
const map = new Map();
for (let i = 0; i < data.length; i++) {
	map.set(data[i], true);
}
const uniqArray = Array.from(map.keys());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.