Module: BenchmarkMethods
- Defined in:
- lib/benchmark_methods.rb,
lib/benchmark_methods/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.2"
Class Method Summary collapse
Class Method Details
.included(base_klass) ⇒ Object
7 8 9 10 11 |
# File 'lib/benchmark_methods.rb', line 7 def self.included(base_klass) base_klass.extend(ClassMethods) interceptor = const_set("#{base_klass.name.demodulize}Interceptor", Module.new) base_klass.send(:prepend, interceptor) end |
.log(report) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/benchmark_methods.rb', line 13 def self.log(report) if Object.const_defined?("Rails") Rails.logger.debug(" --> #{report.label}") Rails.logger.debug(Benchmark::CAPTION) Rails.logger.debug(report.to_s) else puts(" --> #{report.label}") puts(Benchmark::CAPTION) puts(report) end end |
.measure(label, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/benchmark_methods.rb', line 25 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 |