From c328e9b88e602cfb18f12b441a27b92ebaf3400b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 8 Oct 2019 08:08:40 -0500 Subject: [PATCH] Add gsub bench for #5905. --- bench/core/string/bench_gsub.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bench/core/string/bench_gsub.rb diff --git a/bench/core/string/bench_gsub.rb b/bench/core/string/bench_gsub.rb new file mode 100644 index 00000000000..594cb0093b8 --- /dev/null +++ b/bench/core/string/bench_gsub.rb @@ -0,0 +1,19 @@ +str1 = 'white chocolate' +str2 = 'a1' +str3 = 'dog' + +regex2 = /\d/ +regex3 = /\w+/ + +benchmark 'gsub-string' do + + r1 = str1.gsub('white', 'dark') +end + +benchmark "gsub-regex" do + r2 = str2.gsub(regex2, '2') +end + +benchmark "gsub-regex-block" do + r3 = str3.gsub(regex3) { |animal| animal == 'dog' ? 'cat' : 'dog' } +end