Skip to content

Instantly share code, notes, and snippets.

@jodosha
Created June 21, 2009 16:36
Show Gist options
  • Save jodosha/133556 to your computer and use it in GitHub Desktop.
Save jodosha/133556 to your computer and use it in GitHub Desktop.
require "benchmark"
CONDITION = false
ONE = 1
Benchmark.bm(30) do |b|
b.report("if not true") do
counter = 0
5_000_000.times { counter += ONE if !CONDITION }
end
b.report("unless false") do
counter = 0
5_000_000.times { counter += ONE unless CONDITION }
end
end
__END__
                                    user     system      total        real
if not true                     2.000000   0.010000   2.010000 (  2.019511)
unless false                    1.980000   0.010000   1.990000 (  1.994921)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment