Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Type discriminators
(version: 0)
Measure the performance of instanceOf operator vs comparing other types.
Comparing performance of:
instanceof vs string discriminant vs number discriminant vs property exists w/ in operator vs constructor comparison
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script> class A { constructor() { this.i = 1 this.n = 'A' this.aOnly = 0 } } A.NAME = 'A' A.NUM = 1 class B { constructor() { this.i = 2 this.n = 'B' this.bOnly = 0 } } B.NAME = 'B' B.NUM = 2 </script>
Script Preparation code:
var obj = new A();
Tests:
instanceof
obj instanceof A;
string discriminant
obj.n === A.NAME
number discriminant
obj.i === A.NUM
property exists w/ in operator
'aOnly' in obj
constructor comparison
obj.constructor === A
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
instanceof
string discriminant
number discriminant
property exists w/ in operator
constructor comparison
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
constructor comparison vs. instanceof vs Array.isArray 2
typeof vs instanceof Function vs call
constructor comparison vs. instanceof vs Array.isArray 3
Check object. typeof vs constructor + null check
Check object. typeof vs constructor
Comments
Confirm delete:
Do you really want to delete benchmark?