Last active
October 7, 2019 09:59
-
-
Save tbuehlmann/5574713 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
N = 10_000_000 | |
Benchmark.bmbm do |bm| | |
bm.report('String') do | |
N.times do | |
a = 'foobarfoobarhmm' | |
a.sub('foo', 'BAR') | |
end | |
end | |
bm.report('Regexp') do | |
N.times do | |
a = 'foobarfoobarhmm' | |
a.sub(/foo/, 'BAR') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting result. It is surprise for me that RefExp version can be faster. I was using string for simple cases always.