module BenchmarkMethods

Constants

VERSION

Public Class Methods

included(base_klass) click to toggle source
# File lib/benchmark_methods.rb, line 8
def self.included(base_klass)
  unless const_defined?("#{base_klass.name.demodulize_for_bm}Interceptor")
    base_klass.extend(ClassMethods)
    interceptor = const_set("#{base_klass.name.demodulize_for_bm}Interceptor", Module.new)
    base_klass.send(:prepend, interceptor)
  end
end
log(report) click to toggle source
# File lib/benchmark_methods.rb, line 16
def self.log(report)
  if const_defined?("Rails")
    Rails.logger.debug("  --> #{report.label}")
    Rails.logger.debug("#{Benchmark::CAPTION}#{report.to_s}")
  else
    puts("  --> #{report.label}")
    puts(Benchmark::CAPTION)
    puts(report)
  end
end
measure(label) { || ... } click to toggle source
# File lib/benchmark_methods.rb, line 27
def self.measure(label, &block)
  t0, r0 = Process.times, Time.now
  result = yield
  t1, r1 = Process.times, Time.now
  report = Benchmark::Tms.new(t1.utime  - t0.utime,
                     t1.stime  - t0.stime,
                     t1.cutime - t0.cutime,
                     t1.cstime - t0.cstime,
                     r1 - r0,
                     label)
  BenchmarkMethods::log(report)
  result
end