Slice vs Filter vs splice

Benchmark created on


Setup

const x = [];

const indexToRemove = 687_547;

for (let i = 0; i < 1_000_000; i++) {
	x.push(i);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Filter
const result = x.filter((_, i) => i !== indexToRemove)
ready
Slice
const result = [
	...x.slice(0, indexToRemove),
	...x.slice(indexToRemove + 1)
]
ready
Splice
const dupl = [...x]

dupl.splice(x, 1)

const result = dupl
ready

Revisions

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