splice() to update one element vs []

Benchmark created on


Setup

const length = 10000;
const arr = Array.from({ length }, (_, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
array indexing
for (let i = 0; i < length; i++) {
	arr[i] = length - 1 - i;
}
ready
splice
for (let i = 0; i < length; i++) {
	arr.splice(i, 1, length - 1 - i);
}
ready

Revisions

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