Splice vs. [...Spread]

Benchmark created on


Description

When resetting an array (from source), is it faster to destroy and re-create, or to replace with Splice.

Setup

var list1 = [];
var list2 = [];
for (let x = 0; x < 200; x++) {
  list1.push(Math.floor(Math.random() * 1000));
  list2.push(Math.floor(Math.random() * 1000));
}
var intAsc = (a, b) => a - b;
list1.sort(intAsc);
list2.sort(intAsc);

Test runner

Ready to run.

Testing in
TestOps/sec
Splice
list2.splice(0, 200, [...list1]);
ready
Spread
list2 = [...list1];
ready
Loop
for (let x = 0; x < 200; x++) {
	list2[x] = list1[x];
}
ready

Revisions

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