Array.push vs. Array.unshift w/ access

Benchmark created on


Setup

const apush = [];
const aunshift = [];
const cycleCount = 100;

Test runner

Ready to run.

Testing in
TestOps/sec
Array.push & [.length -1]
for (let i=0; i<cycleCount; i++) {
	apush.push(i);
	const foo = apush[apush.length - 1];
}
ready
Array.unshift & [0]
for (let i=0; i<cycleCount; i++) {
	aunshift.unshift(i);
	const foo = aunshift[0];
}
ready

Revisions

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