Unique Array (v2)

Revision 2 of this benchmark created on


Description

Test 1 freezes for 1_000_000

Setup

const arr = Array(10_000).fill(undefined).map((_, i) => i)

Test runner

Ready to run.

Testing in
TestOps/sec
filter => findIndex
arr.filter(
    (v, i) => arr.findIndex(v2 => v === v2) === i
);
ready
Set check
const seen = new Set();
const newArr = [];
arr.forEach(v => {
	if (!seen.has(v)) {
		seen.add(v);
		newArr.push(v);
	}
});
ready
Set spread
[...new Set(arr)]
ready

Revisions

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