Script Preparation code:
Tests:

Historical Performance Data aggregated from 7 community runs

Desktop Results:
Chrome 7 runs
Using String.slice()
879/s
Using String.slice() without a pre-calculated suffix length
872/s
Using String.substring() with a magic number
868/s
Using String.substring() with a lastIndexOf() search
361/s
Using String.replace()
302/s

Fastest: Using String.slice() (2.9x faster)

View exact numbers
  • Using String.slice(): 879 ops/sec
  • Using String.slice() without a pre-calculated suffix length: 872 ops/sec
  • Using String.substring() with a magic number: 868 ops/sec
  • Using String.substring() with a lastIndexOf() search: 361 ops/sec
  • Using String.replace(): 302 ops/sec

Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.

Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results
  • Test case name Result
    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

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 28 days ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:152.0) Gecko/20100101 Firefox/152.0
Firefox 152 on Mac OS X 10.15
View result in a separate tab
Using String.replace()
125/s
Using String.substring() with a magic number
97/s
Using String.substring() with a lastIndexOf() search
95/s
Using String.slice() without a pre-calculated suffix length
31/s
Using String.slice()
29/s
View exact numbers
Test name Executions per second
Using String.replace() 125 Ops/sec
Using String.substring() with a magic number 97 Ops/sec
Using String.substring() with a lastIndexOf() search 95 Ops/sec
Using String.slice() without a pre-calculated suffix length 31 Ops/sec
Using String.slice() 29 Ops/sec