values vs for-in (v2)

Revision 2 of this benchmark created on


Setup

const myObject = {};
for (let i = 0; i < 10000; i++) {
	myObject[`property-${Math.floor(Math.random() * 100000)}`] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
for in
let sum = 0;
for (const property in myObject) {
	if (myObject.hasOwnProperty(property)) {
		sum += myObject[property];
	}
}
ready
object values
let sum2 = 0;
Object.values(myObject).forEach((value) => sum2 += value);
ready

Revisions

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