Module: BenchmarkInterface::Backends::Bm
- Defined in:
- lib/benchmark-interface/backends/benchmark.rb
Constant Summary collapse
- MIN_SAMPLING_TIME =
seconds
0.1
Class Method Summary collapse
Class Method Details
.run(benchmark_set, names, options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/benchmark-interface/backends/benchmark.rb', line 15 def self.run(benchmark_set, names, ) # If we don't remove these we'll get a warning when we load the real # implementation. ::Benchmark.send(:remove_const, :CAPTION) if defined?(::Benchmark::CAPTION) ::Benchmark.send(:remove_const, :FORMAT) if defined?(::Benchmark::FORMAT) benchmark_interface_original_require 'benchmark' unless ['--no-scale'] min_time = benchmark_set.benchmarks.map(&:basic_iteration_time).min if min_time < MIN_SAMPLING_TIME short_iterations = true samples = (MIN_SAMPLING_TIME / min_time / MIN_SAMPLING_TIME).to_i puts "These are short benchmarks - we're running each #{samples} times so they take about a second" end end label_width = benchmark_set.benchmarks(names).map(&:name).map(&:size).max block = Proc.new do |x| benchmark_set.benchmarks(names).each do |benchmark| block = benchmark.block if short_iterations x.report(benchmark.name) do samples.times do block.call end end else x.report(benchmark.name, &benchmark.block) end end end if self == BmBm ::Benchmark.bmbm label_width, &block else ::Benchmark.bm label_width, &block end end |