Compares String.prototype.startsWith against an anchored regular expression for prefix matching.
var iterations = 2000000;0x0D
var s = "hello world";s.startsWith("hello")/^hello/.test(s)s.startsWith("hello")/^hello/.test(s)s.startsWith("hello")/^hello/.test(s)
| Browser | Snippet A | Snippet B | Winner |
|---|---|---|---|
| 19.00 ms | 31.00 ms | Snippet A1.63× faster | |
| 23.00 ms | 6.00 ms | Snippet B3.83× faster |
Median of 5 trials × 2,000,000 iterations per snippet.