Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'benchmark'
array = File.readlines('dutch.bin') # 10k lines
Benchmark.bmbm do |x|
x.report {
x.report("tr") { array.each { |line| line.tr('e', 'z') } }
}
end
Benchmark.bmbm do |x|
x.report {
x.report("sub") { array.each { |line| line.sub('e', 'z') } }
}
end
Benchmark.bmbm do |x|
x.report {
x.report("gsub") { array.each { |line| line.gsub('e', 'z') } }
}
end
@evaneykelen

This comment has been minimized.

Copy link
Owner Author

commented Jul 30, 2019

Rehearsal ------------------------------------
   0.000006   0.000001   0.000007 (  0.000004)
tr  0.017218   0.000534   0.017752 (  0.017801)
--------------------------- total: 0.017759sec

       user     system      total        real
   0.000011   0.000002   0.000013 (  0.000009)
tr  0.014187   0.000213   0.014400 (  0.014438)
tr  0.014113   0.000129   0.014242 (  0.014255)


Rehearsal ------------------------------------
   0.000004   0.000001   0.000005 (  0.000003)
sub  0.005869   0.000099   0.005968 (  0.005974)
--------------------------- total: 0.005973sec

       user     system      total        real
   0.000006   0.000001   0.000007 (  0.000004)
sub  0.006035   0.000278   0.006313 (  0.006323)
sub  0.006122   0.000116   0.006238 (  0.006238)


Rehearsal ------------------------------------
   0.000004   0.000001   0.000005 (  0.000003)
gsub  0.044664   0.000257   0.044921 (  0.044961)
--------------------------- total: 0.044926sec

       user     system      total        real
   0.000007   0.000011   0.000018 (  0.000005)
gsub  0.044989   0.000273   0.045262 (  0.045308)
gsub  0.044771   0.000155   0.044926 (  0.045026)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.