for vs reduce

Benchmark created on


Setup

const rooms = Array.apply(null, Array(90000))
    .map(function (y, i) { return Object.assign({}, {id: i, acl: Math.random()}) });


let count = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (const room of rooms) {
	if (room.acl > 0.5) {
		count++;
	}
}
ready
reduce
count = rooms.reduce((acc, current) => {
	if (current.acl > 0.5) {
		return acc+1;
	}
	return acc;
}, 0)
ready

Revisions

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