Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Instanceof vs string comparison vs property checking vs constructor comparison
Measure the performance of instanceOf operator vs comparing a basic string type.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 12; Mobile; rv:138.0) Gecko/138.0 Firefox/138.0
Browser:
Firefox Mobile 138
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
string type
353.1M/s
constructor comparison
352.7M/s
string type + undefined
352.0M/s
property
350.4M/s
instanceof
23.6M/s
View exact numbers
Test name
Executions per second
✓
string type
353,128,384 Ops/sec
constructor comparison
352,672,384 Ops/sec
string type + undefined
351,991,616 Ops/sec
property
350,425,568 Ops/sec
instanceof
23,635,894 Ops/sec
HTML Preparation code:
<script> class TestClass { constructor() { this.a = 2; this.t = 'mesh'; } } </script>
Script Preparation code:
var obj = new TestClass();
Tests:
instanceof
obj instanceof TestClass;
string type
obj.t === 'mesh'
string type + undefined
obj.t !== undefined
property
obj.a !== undefined
constructor comparison
obj.constructor === TestClass