instanceof vs string
Measure the performance of instanceOf operator vs comparing a basic string type.
Date tested:
one year ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 OPR/89.0.4447.64 (Edition GX-CN)
Test name
Executions per second
instanceof
5453667.0 Ops/sec
string type
14083800.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script> class TestClass { constructor() { this.a = 2; this.t = 'TABLE_ROW_HEIGHT_CHANGE'; } } </script>
Script Preparation code:
var obj = new TestClass();
Tests:
instanceof
obj instanceof TestClass;
string type
obj.t === 'mesh'
Open this result on MeasureThat.net