reducesum

Benchmark created on


Setup

const lst = [];

for (let i =0; i < 1000; i +=1){
	lst.push({
		x: Math.random(),
		y: Math.random(),
	})
}

Test runner

Ready to run.

Testing in
TestOps/sec
normalreduce
lst.reduce((acc, el) => ({x: acc.x+el.x, y:acc.y + el.y}), {x: 0, y:0});
ready
optimized
lst.reduce((acc, el) => {
	acc.x += el.x;
	acc.y += el.y;
	return acc;
}, {x: 0, y:0});
ready
forloop
acc = {x: 0, y:0};

for (const el of lst) {
	acc.x += el.x;
	acc.y += el.y;
}
ready
for index
acc = {x: 0, y:0};

for (let i =0; i < lst.length; i +=1 ) {
	acc.x += lst[i].x;
	acc.y += lst[i].y;
}
ready

Revisions

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