regexp .test() vs string .match() vs indexOf === 0 vs string .startsWith()Fastest: indexOf === 0 (1.8x faster)
27,733,116 ops/sec
20,758,642 ops/sec
18,033,082 ops/sec
15,057,943 ops/sec
Fastest: string .startsWith() (65.3x faster)
1,241,519,616 ops/sec
1,192,801,024 ops/sec
37,859,568 ops/sec
19,008,640 ops/sec
Fastest: indexOf === 0 (1.7x faster)
30,282,676 ops/sec
26,339,190 ops/sec
21,756,602 ops/sec
17,803,916 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| regexp .test() | |
| string .match() | |
| indexOf === 0 | |
| string .startsWith() |
| Test name | Executions per second |
|---|---|
| ✓ indexOf === 0 | 250,359,744 Ops/sec |
| string .startsWith() | 93,625,504 Ops/sec |
| regexp .test() | 81,914,960 Ops/sec |
| string .match() | 48,623,404 Ops/sec |