Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
Firefox 150
Windows
Desktop
one month ago
Test name Executions per second
Using String.replace() 79.5 Ops/sec
Using String.substring() with a lastIndexOf() search 50.1 Ops/sec
Using String.substring() with a magic number 61.7 Ops/sec
Using String.slice() 60.7 Ops/sec
Using String.slice() without a pre-calculated suffix length 61.6 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