hasOwnProperty vs Object.keys

Benchmark created on


Setup

function Obj(){}
Obj.prototype.own0 = 0;
var obj = new Obj();
for (let i = 0; i < 1000; i++) {
	obj[`key${i}`] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
for (const key in obj) obj.hasOwnProperty(key);
ready
Object.keys
for (const key of Object.keys(obj));
ready

Revisions

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