Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36
Chrome 101
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
slice 204065376.0 Ops/sec
startsWith 30275794.0 Ops/sec
Tests:
  • slice

    x
     
    const fullHouseNumber = '1/23A';
    const prefix = fullHouseNumber.slice(0, 5);
      if (prefix === 'Unit ' || prefix === 'Flat ');
      const prefix2 = fullHouseNumber.slice(0, 10);
      if (prefix2 === 'Apartment ');
  • startsWith

     
    const fullHouseNumber = '1/23A';
    if (
        fullHouseNumber.startsWith('Unit ') ||
        fullHouseNumber.startsWith('Flat ')
      );
      if (fullHouseNumber.startsWith('Apartment '));