random deletion array.splice vs set.delete

Benchmark created on


Setup

const NUM_ITEMS = 10;
const array = Array.from({length: NUM_ITEMS}, (_, i) => i);

const set = new Set(array);
const toRemove = Math.random() * NUM_ITEMS | 0;

Test runner

Ready to run.

Testing in
TestOps/sec
array.splice
const idx = array.indexOf(toRemove);
if (idx >= 0) {
	array.splice(idx, 1);
}
ready
set.delete
set.delete(toRemove);
ready

Revisions

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