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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser:
Chrome 136
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
instanceof Promise
276040096.0 Ops/sec
then check
281001952.0 Ops/sec
constructor comparison
286094048.0 Ops/sec
Script Preparation code:
const obj = new Promise(() => {}); const obj2 = {}; const obj3 = null; const obj4 = undefined;
Tests:
instanceof Promise (promise)
obj instanceof Promise
instanceof Promise (empty object)
obj2 instanceof Promise
instanceof Promise (null)
obj3 instanceof Promise
then check (promise)
obj?.then
then check (empty object)
obj2?.then
then check (null)
obj3?.then
constructor comparison (promise)
obj?.constructor === Promise
constructor comparison (empty object)
obj2?.constructor === Promise
constructor comparison (null)
obj3?.constructor === Promise
type obj?.then === function (promise)
typeof obj?.then === 'function'
type obj?.then === function (empty object)
typeof obj2?.then === 'function'
type obj?.then === function (null)
typeof obj3?.then === 'function'
then in (promise)
obj && 'then' in obj
then in (empty object)
obj2 && 'then' in obj2
then in (null)
obj3 && 'then' in obj3
instanceof Promise (undefined)
obj instanceof Promise
then check (undefined)
obj4?.then
constructor comparison (undefined)
obj4?.constructor === Promise
type obj?.then === function (undefined)
typeof obj4?.then === 'function'
then in (undefined)
obj4 && 'then' in obj4