instanceof Promise (promise) vs instanceof Promise (empty object) vs instanceof Promise (null) vs then check (promise) vs then check (empty object) vs then check (null) vs constructor comparison (promise) vs constructor comparison (empty object) vs constructor comparison (null) vs type obj?.then === function (promise) vs type obj?.then === function (empty object) vs type obj?.then === function (null) vs then in (promise) vs then in (empty object) vs then in (null) vs instanceof Promise (undefined) vs then check (undefined) vs constructor comparison (undefined) vs type obj?.then === function (undefined) vs then in (undefined)Fastest: instanceof Promise (null) (1.3x faster)
281,329,920 ops/sec
279,110,336 ops/sec
277,024,768 ops/sec
274,690,304 ops/sec
272,032,704 ops/sec
270,843,008 ops/sec
270,145,664 ops/sec
270,014,592 ops/sec
269,355,904 ops/sec
268,432,352 ops/sec
259,397,024 ops/sec
257,449,760 ops/sec
255,866,288 ops/sec
255,511,488 ops/sec
223,709,696 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| instanceof Promise (promise) | |
| instanceof Promise (empty object) | |
| instanceof Promise (null) | |
| then check (promise) | |
| then check (empty object) | |
| then check (null) | |
| constructor comparison (promise) | |
| constructor comparison (empty object) | |
| constructor comparison (null) | |
| type obj?.then === function (promise) | |
| type obj?.then === function (empty object) | |
| type obj?.then === function (null) | |
| then in (promise) | |
| then in (empty object) | |
| then in (null) | |
| instanceof Promise (undefined) | |
| then check (undefined) | |
| constructor comparison (undefined) | |
| type obj?.then === function (undefined) | |
| then in (undefined) |
| Test name | Executions per second |
|---|---|
| ✓ instanceof Promise (promise) | 303,837,824 Ops/sec |
| then check (promise) | 298,302,976 Ops/sec |
| instanceof Promise (null) | 290,129,280 Ops/sec |
| then in (null) | 285,495,616 Ops/sec |
| constructor comparison (promise) | 277,396,320 Ops/sec |
| then in (promise) | 277,073,248 Ops/sec |
| constructor comparison (null) | 273,117,664 Ops/sec |
| type obj?.then === function (promise) | 269,327,680 Ops/sec |
| then check (null) | 265,423,008 Ops/sec |
| then in (empty object) | 262,307,344 Ops/sec |
| constructor comparison (empty object) | 260,667,152 Ops/sec |
| type obj?.then === function (null) | 260,597,456 Ops/sec |
| type obj?.then === function (empty object) | 257,449,760 Ops/sec |
| then check (empty object) | 254,150,944 Ops/sec |
| instanceof Promise (empty object) | 241,658,960 Ops/sec |