Actions
Patch #40008
closedReplace String#sub with delete_prefix / delete_suffix
Description
The attached patch replaces `String#sub` which is used to remove leading or trailing substring with String#delete_prefix and String#delete_suffix introduced in Ruby 2.5.
The change improves the efficiency and readability of the code.
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
'#123'.delete_prefix('#')
1.497M i/100ms
'#123'.sub('^#', '') 936.977k i/100ms
Calculating -------------------------------------
'#123'.delete_prefix('#')
14.822M (± 0.5%) i/s - 74.837M in 5.049042s
'#123'.sub('^#', '') 9.322M (± 1.2%) i/s - 46.849M in 5.026072s
Comparison:
'#123'.delete_prefix('#'): 14822395.1 i/s
'#123'.sub('^#', ''): 9322431.1 i/s - 1.59x slower
Files
Updated by Go MAEDA almost 2 years ago
Updated by Go MAEDA almost 2 years ago
- Status changed from New to Closed
- Assignee set to Go MAEDA
Committed the patch in r22596.
Actions