Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Chrome 127
Mac OS X 10.15.7
Desktop
8 months ago
Test name Executions per second
RegExp replace 4351416.0 Ops/sec
String ops 11359012.0 Ops/sec
Tests:
  • RegExp replace

    x
     
    const strip = (str) => str.replace(/\/?index$/, '');
    strip('en/index');
    strip('index');
    strip('en/guides/getting-started');
  • String ops

     
    const strip = (str) => str === 'index' ? '' :  str.endsWith('/index') ? str.slice(0, -6) : str;
    strip('en/index');
    strip('index');
    strip('en/guides/getting-started');