Module: ABProf

Defined in:
lib/abprof.rb,
lib/abprof/benchmark_dsl.rb

Overview

Protocol:

Controller sends "ITERS [integer]\n"
Controller sends "QUIT\n" when done
Test process responds with "NOT OK\n" or crashes for bad results
Test process responds with "VALUE 27.23432" to explicitly return a single value
Test process responds with "VALUES [1.4, 2.714, 39.4, -71.4]" to explicitly return many values
  QUIT requires no response.

Defined Under Namespace

Classes: ABBareProcess, ABHarnessProcess, ABWorker, BenchmarkInstance

Constant Summary collapse

PROPERTIES =

These are primarily for DSL use.

[ :debug, :pvalue, :iters_per_trial, :min_trials, :max_trials, :burnin, :bare, :fail_on_divergence ]
SUMMARY_TYPES =
{
  "mean" => proc { |samples|
    samples.inject(0.0, &:+) / samples.size
  },
  "median" => proc { |samples|
    sz = samples.size
    sorted = samples.sort
    if sz % 2 == 1
      # For odd-length, take middle element
      sorted[ samples.size / 2 ]
    else
      # For even length, mean of two middle elements
      (sorted[ sz / 2 ] + sorted[ sz / 2 + 1 ]) / 2.0
    end
  },
}
SUMMARY_METHODS =
SUMMARY_TYPES.keys

Class Method Summary collapse

Class Method Details

.compare(opts = {}, &block) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/abprof/benchmark_dsl.rb', line 146

def self.compare(opts = {}, &block)
  c = ABProf::BenchmarkInstance.new
  c.instance_eval &block

  raise "A DSL file must declare exactly two reports!" unless c.reports.size == 2

  unless opts[:no_at_exit]
    at_exit do
      puts "Exit handler" if opts[:print_output]
      c.run_sampling opts
    end
  end

  c
end

.debugObject



14
15
16
# File 'lib/abprof.rb', line 14

def self.debug
  @debug
end

.debug=(new_val) ⇒ Object



17
18
19
# File 'lib/abprof.rb', line 17

def self.debug=(new_val)
  @debug = new_val
end

.summarize(method, samples) ⇒ Object



123
124
125
126
127
# File 'lib/abprof.rb', line 123

def self.summarize(method, samples)
  raise "Unknown summary method #{method.inspect}!" unless SUMMARY_METHODS.include?(method.to_s)
  method_proc = SUMMARY_TYPES[method.to_s]
  method_proc.call(samples)
end