module QuickBenchmark

Constants

TimeTest
VERSION

Public Class Methods

iterations_given(amount) click to toggle source
# File lib/quick_benchmark.rb, line 22
def self.iterations_given(amount)
  if amount.respond_to? :count
    amount.count
  else
    amount
  end
end

Public Instance Methods

benchmark(iterations = 100, &tests) click to toggle source
# 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) click to toggle source
# File lib/quick_benchmark.rb, line 30
def time(label, &method)
  t = TimeTest.new label.to_s, method
  @tests.push t
end