summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-11-20 13:48:34 +0100
committerJean Boussier <jean.boussier@gmail.com>2023-11-20 14:33:20 +0100
commit83c385719d95c178790e52f78e2b247d1476eb5e (patch)
tree9dae5511963e8d129ce87bbd8d8cd4a8dbe1c29d /benchmark
parent701b0650de8a5b1436ce1abc65e0fcc2be480c2d (diff)
Specialize String#dup
`String#+@` is 2-3 times faster than `String#dup` because it can directly go through `rb_str_dup` instead of using the generic much slower `rb_obj_dup`. This fact led to the existance of the ugly `Performance/UnfreezeString` rubocop performance rule that encourage users to rewrite the much more readable and convenient `"foo".dup` into the ugly `(+"foo")`. Let's make that rubocop rule useless. ``` compare-ruby: ruby 3.3.0dev (2023-11-20T02:02:55Z master 701b0650de) [arm64-darwin22] last_commit=[ruby/prism] feat: add encoding for IBM865 (https://github.com/ruby/prism/pull/1884) built-ruby: ruby 3.3.0dev (2023-11-20T12:51:45Z faster-str-lit-dup 6b745bbc5d) [arm64-darwin22] warming up.. | |compare-ruby|built-ruby| |:------|-----------:|---------:| |uplus | 16.312M| 16.332M| | | -| 1.00x| |dup | 5.912M| 16.329M| | | -| 2.76x| ```
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/string_dup.yml7
1 files changed, 7 insertions, 0 deletions
diff --git a/benchmark/string_dup.yml b/benchmark/string_dup.yml
new file mode 100644
index 0000000000..90793f9f2a
--- /dev/null
+++ b/benchmark/string_dup.yml
@@ -0,0 +1,7 @@
+prelude: |
+ # frozen_string_literal: true
+benchmark:
+ uplus: |
+ +"A"
+ dup: |
+ "A".dup