Key loops

Benchmark created on


Setup

const a = {};
for (let i = 0; i < 1000; i++) {
	a[i] = true;
}

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
const b = {};
Object.keys(a).forEach((key) => b[key] = false);
ready
for in
const c = {};
for (const key in a) {
	c[key] = false;	
}
ready
reduce
Object.keys(a).reduce((acc, v) => {
	acc[v] = false;
	return acc;
}, {})
ready

Revisions

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