Module: SimpleBench

Defined in:
lib/simple_bench.rb

Overview

Implementation of SimpleBench gem

Class Method Summary collapse

Class Method Details

.n_times(*methods, number_of_times) ⇒ Object

Expects Strings. Runs each method once, and then as many times as specified



16
17
18
19
20
21
22
23
24
# File 'lib/simple_bench.rb', line 16

def n_times(*methods, number_of_times)
  Benchmark.bmbm do |x|
    methods.each do |method|
      x.report("#{method}_once") { send(method) }
    end

    run_multiple_times(x, number_of_times, methods)
  end
end

.simple(*methods) ⇒ Object

Expects Strings. Runs each method once.



7
8
9
10
11
12
13
# File 'lib/simple_bench.rb', line 7

def simple(*methods)
  Benchmark.bmbm do |x|
    methods.each do |method|
      x.report("#{method}_once") { send(method) }
    end
  end
end

.tiered(*methods) ⇒ Object

Expects Strings. Runs each method once, and then 1_000 times, 20_000 times, and 75_000 times



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simple_bench.rb', line 28

def tiered(*methods)
  Benchmark.bmbm do |x|
    tiers = [1_000, 20_000, 75_000]

    methods.each do |method|
      x.report("#{method}_once") { send(method) }
    end

    tiers.each do |tier|
      run_multiple_times(x, tier, methods)
    end
  end
end