Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Chrome 142
Windows
Desktop
5 months ago
Test name Executions per second
Using String.replace() 272.6 Ops/sec
Using String.substring() with a lastIndexOf() search 339.9 Ops/sec
Using String.substring() with a magic number 626.6 Ops/sec
Using String.slice() 667.4 Ops/sec
Using String.slice() without a pre-calculated suffix length 668.8 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