Skip to content

Instantly share code, notes, and snippets.

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

This comment has been minimized.

Copy link
Owner Author

commented Jul 30, 2019

Result:

   user     system      total        real
0.017227   0.000306   0.017533 (  0.017533)
   user     system      total        real
0.006544   0.000593   0.007137 (  0.007147)
   user     system      total        real
0.042544   0.000314   0.042858 (  0.042901)
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.