Skip to content

Commit

Permalink
Add gsub bench for #5905.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 8, 2019
1 parent 80455ae commit c328e9b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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

0 comments on commit c328e9b

Please sign in to comment.