Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0 pagestrip-debug
Firefox 110
Mac OS X 10.15
Desktop
one month ago
Test name Executions per second
.startsWith() 273910.3 Ops/sec
RegExp 5732.0 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++;
    }