jodosha (owner)

Revisions

gist: 133556 Download_button fork
public
Public Clone URL: git://gist.github.com/133556.git
Embed All Files: show embed
boolean_test_benchmark.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)