Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0
Chrome 143
Windows
Desktop
3 months ago
Test name Executions per second
Using String.replace() 164.3 Ops/sec
Using String.substring() with a lastIndexOf() search 173.2 Ops/sec
Using String.substring() with a magic number 284.4 Ops/sec
Using String.slice() 334.2 Ops/sec
Using String.slice() without a pre-calculated suffix length 271.3 Ops/sec
Script Preparation code:
Tests:
  • Using String.replace()

  • Using String.substring() with a lastIndexOf() search

  • Using String.substring() with a magic number

  • Using String.slice()

  • Using String.slice() without a pre-calculated suffix length