Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Chrome 134
Mac OS X 10.15.7
Desktop
one month ago
Test name Executions per second
.startsWith() 19908.8 Ops/sec
RegExp 6035.3 Ops/sec
Script Preparation code:
AخA
 
const regexp = new RegExp(/^\-\-/);
const prefix = "--";
const str = "--some-var";
const numTests = 10000;
Tests:
  • .startsWith()

    x
     
    let i = 0;
    while (i < numTests) {
        str.startsWith(prefix);
        i++;
    }
  • RegExp

     
    let i = 0;
    while (i < numTests) {
        regexp.test(str);
        i++;
    }