Array push vs splice vs concat vs spread construct (v4)

Revision 4 of this benchmark created on


Setup

let a = Array.from(Array(250).keys()).map(x=> `hello ${x}`);

Test runner

Ready to run.

Testing in
TestOps/sec
append using push
let b = [];
for (let i=0; i<1000; i++) {
	b.push(...a);
}
ready
append using splice
let b = [];
for (let i=0; i<1000; i++) {
	b.splice(b.length, 0, ...a);
}
ready
appending using concat
let b = [];
for (let i=0; i<1000; i++) {
	b=b.concat(a);
}
ready
appending using spread construct
let b = [];
for (let i=0; i<1000; i++) {
	b=[...b, ...a];
}
ready

Revisions

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