Push or resize

Benchmark created on


Setup

const a = [];
const b = [];
for (let i = 0; i < 1000; i++)
{
	a.push(i);
	b.push(i % 3 !== 0);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Push
for (let k = 0; k < 1000; k++)
{
	const c = [];
	for (let i = 0; i < a.length; i++)
		if (b[i])
			c.push(a[i]);
}
ready
Resize
for (let k = 0; k < 1000; k++)
{
	const c = new Array(a.length);
	let index = 0;
	for (let i = 0; i < a.length; i++)
		if (b[i])
			c[index++] = a[i];
	c.length = index;
}
ready

Revisions

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