diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-12 15:50:15 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-12 19:58:58 +0900 |
commit | 693f7ab31578bf23d165f022b60da3a32055ceea (patch) | |
tree | 0161e10584625e3e2ccc84c32778b8486790e6e2 /benchmark | |
parent | 2e7d886311399a2ec1918afe7838d12e7708b7a6 (diff) | |
download | ruby-693f7ab31578bf23d165f022b60da3a32055ceea.tar.gz |
Optimize String#split
Optimized `String#split` with `/ /` (single space regexp) as
simple string splitting. [ruby-core:98272]
| |compare-ruby|built-ruby|
|:--------------|-----------:|---------:|
|re_space-1 | 432.786k| 1.539M|
| | -| 3.56x|
|re_space-10 | 76.231k| 191.547k|
| | -| 2.51x|
|re_space-100 | 8.152k| 19.557k|
| | -| 2.40x|
|re_space-1000 | 837.405| 2.022k|
| | -| 2.41x|
ruby-core:98272: https://bugs.ruby-lang.org/issues/15771#change-85511
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/string_split.yml | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/benchmark/string_split.yml b/benchmark/string_split.yml index 84ffe8f6a7..ac6ed0d72f 100644 --- a/benchmark/string_split.yml +++ b/benchmark/string_split.yml @@ -1,7 +1,18 @@ prelude: | - str0 = [*0..9].join("") + str1 = [*0..5].join(" ") + " " + str10 = str1 * 10 + str100 = str10 * 10 + str1000 = str100 * 10 benchmark: - to_chars-1: str0.split('') - to_chars-10: (str0 * 10).split('') - to_chars-100: (str0 * 100).split('') - to_chars-1000: (str0 * 1000).split('') + to_chars-1: str1.split('') + to_chars-10: str10.split('') + to_chars-100: str100.split('') + to_chars-1000: str1000.split('') + to_words-1: str1.split(' ') + to_words-10: str10.split(' ') + to_words-100: str100.split(' ') + to_words-1000: str1000.split(' ') + re_space-1: str1.split(/ /) + re_space-10: str10.split(/ /) + re_space-100: str100.split(/ /) + re_space-1000: str1000.split(/ /) |