Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
instanceof vs in options
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
instanceof test
157504400.0 Ops/sec
in test
1553290624.0 Ops/sec
instanceof test again
160112240.0 Ops/sec
proper type check
1387363968.0 Ops/sec
includes check
45093188.0 Ops/sec
Script Preparation code:
class ClassFoo { constructor() { this.bar = 'classFoo'; } } var knownTypes = ['otherClass', 'classFoo']; var Foo = ClassFoo; var foo = new Foo();
Tests:
instanceof test
foo instanceof Foo
in test
'bar' in foo
instanceof test again
foo instanceof Foo
proper type check
'bar' in foo && (foo.bar === 'otherClass' || foo.bar === 'classFoo')
includes check
'bar' in foo && knownTypes.includes(foo.bar)