For…in vs Object.keys + For…of

Benchmark created on


Setup

var foo = Array(100).fill(null).reduce((acc, _, index) => {
	acc['key' + (index + 1)] = index + 1;
	return acc;
}, {});

Test runner

Ready to run.

Testing in
TestOps/sec
For…in
for (const key in foo) {
	foo[key] = foo[key] * 10;
}
ready
Object.keys + For…of
let keys = Object.keys(foo);
for (const key of keys) {
	foo[key] = foo[key] * 10;
}
ready

Revisions

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