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

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
append using push
let a = Array.from(Array(250).keys()).map(x=> `hell ${x}`);
let b = [];
for (let i=0; i<1000; i++) {
	b.push(...a);
}
ready
append using splice
let a = Array.from(Array(250).keys()).map(x=> `hell ${x}`);
let b = [];
for (let i=0; i<1000; i++) {
	b.splice(b.length, 0, ...a);
}
ready
appending using concat
let a = Array.from(Array(250).keys()).map(x=> `hell ${x}`);
let b = [];
for (let i=0; i<1000; i++) {
	b=b.concat(a);
}
ready
appending using spread construct
let a = Array.from(Array(250).keys()).map(x=> `hell ${x}`);
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.