Module: QuickBenchmark

Defined in:
lib/quick_benchmark.rb,
lib/quick_benchmark/version.rb

Defined Under Namespace

Classes: TimeTest

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.iterations_given(amount) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/quick_benchmark.rb', line 22

def self.iterations_given(amount)
  if amount.respond_to? :count
    amount.count
  else
    amount
  end
end

Instance Method Details

#benchmark(iterations = 100, &tests) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/quick_benchmark.rb', line 9

def benchmark(iterations = 100, &tests)
  @tests = []
  tests.call
  iterations = QuickBenchmark.iterations_given(iterations)
  Benchmark.bmbm(7) do |x|
    @tests.each do |test|
      x.report(test.label) do
        iterations.times { test.method }
      end
    end
  end
end

#time(label, &method) ⇒ Object



30
31
32
33
# File 'lib/quick_benchmark.rb', line 30

def time(label, &method)
  t = TimeTest.new label.to_s, method
  @tests.push t
end