hasOwnProperty vs in

Benchmark created on


Description

Compare for usge in if-clauses.

Setup

const noProto = { a: 'a', b: 1};

const noProtoLarger = {
	a: 'a',
	b: 1,
	c: 'hello',
	d: false,
	e: 'no brainer',
	f: {g: 'go'}
};


function CreateProto() {
	this.a = 'a';
}


CreateProto.prototype.b = 1;

const p = new CreateProto();

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty a noProto
const r = noProto.hasOwnProperty('a');
ready
hasOwnProperty a noProtoLarger
const r = noProtoLarger.hasOwnProperty('a');
ready
hasOwnProperty a proto
const r = p.hasOwnProperty('a');
ready
hasOwnProperty b proto
const r = p.hasOwnProperty('b');
ready
hasOwnProperty b noProto
const r = noProto.hasOwnProperty('b');
ready
hasOwnProperty b noProtoLarger
const r = noProtoLarger.hasOwnProperty('b');
ready
in b noProto
const r = 'b' in noProto;
ready
in b noProtoLarger
const r = 'b' in noProtoLarger;
ready
in b proto
const r = 'b' in p;
ready
in a proto
const r = 'a' in p;
ready

Revisions

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