Module: SimpleBench

Defined in:
lib/simple_bench.rb

Class Method Summary collapse

Class Method Details

.n_times(method_1, method_2, n) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/simple_bench.rb', line 10

def n_times(method_1, method_2, n)
  Benchmark.bmbm do |x|
    x.report("#{method_1}_once") { send(method_1) }
    x.report("#{method_2}_once") { send(method_2) }
    x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
    x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
  end
end

.simple(method_1, method_2) ⇒ Object



3
4
5
6
7
8
# File 'lib/simple_bench.rb', line 3

def simple(method_1, method_2)
  Benchmark.bmbm do |x|
    x.report("#{method_1}_once") { send(method_1) }
    x.report("#{method_2}_once") { send(method_2) }
  end
end

.tiered(method_1, method_2) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/simple_bench.rb', line 19

def tiered(method_1, method_2)
  Benchmark.bmbm do |x|
    x.report("#{method_1}_once") { send(method_1) }
    x.report("#{method_2}_once") { send(method_2) }

    n = 1_000
    x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
    x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }

    n = 10_000
    x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
    x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }

    n = 100_000
    x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
    x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
  end
end