slice vs splice

Benchmark created on


Setup

const arr = [];
for (let i = 0; i < 1000000; i += 1) {
	arr[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
slice
let sliced;
let j;
for (j = 0; j < arr.length; j += 1000) {
	new_arr = arr.slice(j, 1000);
}
ready
splice
let spliced;
let j;
while (arr.length) {
	spliced = arr.splice(0, 1000);
}
ready

Revisions

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