Skip to content

Instantly share code, notes, and snippets.

@atroche
Created November 24, 2014 04:34
Show Gist options
  • Save atroche/d990b846e4d7d9df2701 to your computer and use it in GitHub Desktop.
Save atroche/d990b846e4d7d9df2701 to your computer and use it in GitHub Desktop.
require 'rubyperf'
m = Perf::Meter.new
result2=m.measure(:bang) do
10000000.times do
"asdf".sub!(/a/, "")
end
end
result1=m.measure(:non_bang) do
10000000.times do
"asdf".sub(/a/, "")
end
end
puts m.report_simple
# measure : percent% accuracy count user system total real
# \blocks : 100.000% excellent 2 14.660000 0.000000 14.660000 ( 14.658286)
# \bang : 46.239% excellent 1 6.780000 0.000000 6.780000 ( 6.776532)
# \non_bang : 53.761% excellent 1 7.880000 0.000000 7.880000 ( 7.881754)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment