Array.push vs Spreading

Benchmark created on


Setup

// Setup code
const newObject = { key: "value" };
const originalArray = Array.from({ length: 10 }, (_, i) => ({ index: i }));

Test runner

Ready to run.

Testing in
TestOps/sec
Spread Operator
// Test case: Spread Operator
originalArray.reduce((acc,item,index) => {
	return {...acc, [index]:item.key}
},{})

ready
Array.prototype.push()
// Test case: Array.prototype.push()
originalArray.reduce((acc,item,index) => {
	acc[index] = item.key;
	return acc;
},{})


ready

Revisions

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