Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
Firefox 150
Windows
Desktop
2 months ago
Using String.replace()
79/s
Using String.substring() with a magic number
62/s
Using String.slice() without a pre-calculated suffix length
62/s
Using String.slice()
61/s
Using String.substring() with a lastIndexOf() search
50/s
View exact numbers
Test name Executions per second
Using String.replace() 79 Ops/sec
Using String.substring() with a magic number 62 Ops/sec
Using String.slice() without a pre-calculated suffix length 62 Ops/sec
Using String.slice() 61 Ops/sec
Using String.substring() with a lastIndexOf() search 50 Ops/sec
Script Preparation code:
Tests: