mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve String#slice! performance
Instead of searching twice to extract and to delete, extract and delete the found position at the first search. This makes faster nearly twice, for regexps and strings. | |compare-ruby|built-ruby| |:-------------|-----------:|---------:| |regexp-short | 2.143M| 3.918M| |regexp-long | 105.162k| 205.410k| |string-short | 3.789M| 7.964M| |string-long | 1.301M| 2.457M|
This commit is contained in:
parent
0dd6f020fc
commit
05229cef45
Notes:
git
2020-01-31 17:56:55 +09:00
2 changed files with 80 additions and 15 deletions
11
benchmark/string_slice.yml
Normal file
11
benchmark/string_slice.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
prelude: |
|
||||
long_string = "x"*1000+"-hår"
|
||||
benchmark:
|
||||
regexp-short: |
|
||||
"x-hår".slice!(/-(.)(.)(.)/, 3)
|
||||
regexp-long: |
|
||||
long_string.dup.slice!(/-(.)(.)(.)/, 3)
|
||||
string-short: |
|
||||
"x-hår".slice!("r")
|
||||
string-long: |
|
||||
long_string.dup.slice!("r")
|
||||
Loading…
Add table
Add a link
Reference in a new issue