Extending Arrays with length or push or spreads

Benchmark created on


Preparation HTML


Setup

const SRC_LEN = 1_000_000;
var TIMES = 500;
var src = [];
var out = [];
for (let i = 0; i < SRC_LEN; i++) {
	src.push(i);
}

Teardown

delete src;
delete out;

Test runner

Ready to run.

Testing in
TestOps/sec
Length and index
for (let t = 0; t < TIMES; t++) {
	const offset = out.length;
	out.length += src.length;

	for (let i = 0; i < src.length; i++)
		out[i + offset] = src[i];
}

ready
Multiple push
for (let t = 0; t < TIMES; t++)
	for (let i = 0; i < src.length; i++)
		out.push(src[i]);

ready
Push spread
for (let t = 0; t < TIMES; t++)
	out.push(...src);
ready

Revisions

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