typeof -> string vs Object.prototype.toString.call -> string vs typeof -> boolean vs Object.prototype.toString.call -> boolean vs typeof -> object vs Object.prototype.toString.call -> object vs typeof -> function vs Object.prototype.toString.call -> functionFastest: typeof -> boolean (2.9x faster)
2,217,571 ops/sec
2,145,464 ops/sec
2,131,187 ops/sec
2,127,069 ops/sec
774,166 ops/sec
772,825 ops/sec
772,244 ops/sec
761,454 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| typeof -> string | |
| Object.prototype.toString.call -> string | |
| typeof -> boolean | |
| Object.prototype.toString.call -> boolean | |
| typeof -> object | |
| Object.prototype.toString.call -> object | |
| typeof -> function | |
| Object.prototype.toString.call -> function |
| Test name | Executions per second |
|---|---|
| ✓ typeof -> string | 27,567,416 Ops/sec |
| typeof -> function | 24,192,610 Ops/sec |
| typeof -> boolean | 15,027,905 Ops/sec |
| typeof -> object | 12,846,283 Ops/sec |
| Object.prototype.toString.call -> function | 4,457,707 Ops/sec |
| Object.prototype.toString.call -> boolean | 4,075,636 Ops/sec |
| Object.prototype.toString.call -> object | 3,999,299 Ops/sec |
| Object.prototype.toString.call -> string | 3,991,418 Ops/sec |