mapped+spread v/s pushed v/s concat

Benchmark created on


Setup

var arr = []

for(let i = 0; i < 20000; i++) {
	arr.push({
		a: i,
		b: Math.random(),
		c: Math.random(),
		d: "bc"
	})
}

Test runner

Ready to run.

Testing in
TestOps/sec
map + spread
const mapped1 = arr.map(({a,b,c,d}) => [a,b,c,d])

const arr2 = [["col1", "col2"], ...mapped1]

arr2.push(["end"])
ready
push els


const arr3 = [["col1", "col2"]];

for(let {a,b,c,d} of arr) {
	arr3.push([a,b,c,d])
}

arr3.push(["end"])
ready
concat
const mapped4 = arr.map(({a,b,c,d}) => [a,b,c,d])
const arr4 =  [["col1", "col2"]]
arr4.concat(mapped4)

arr4.push(["end"])
ready

Revisions

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