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
in test
1553.3M/s
proper type check
1387.4M/s
instanceof test again
160.1M/s
instanceof test
157.5M/s
includes check
45.1M/s
View exact numbers
Test name
Executions per second
✓
in test
1,553,290,624 Ops/sec
proper type check
1,387,363,968 Ops/sec
instanceof test again
160,112,240 Ops/sec
instanceof test
157,504,400 Ops/sec
includes check
45,093,188 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)