for in vs. for of Object.entries

Benchmark created on


Setup

const SIZE = 10000;
const bigObject = {};
for (let i = 0; i < SIZE; i++) {
	bigObject[`key_${i}`] = i;
}
let counter = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
for in
for (const key in bigObject) {
	if (!bigObject.hasOwnProperty(key)) {
		continue;
	}
	counter += bigObject[key];
}
ready
for of Object.entries
for (const key of Object.keys(bigObject)) {
	counter += bigObject[key];
}
ready

Revisions

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