Class: Bench::Runner

Inherits:
Object
  • Object
show all
Includes:
Alf::Iterator
Defined in:
lib/bench/runner.rb

Instance Method Summary (collapse)

Constructor Details

- (Runner) initialize(defn)

A new instance of Runner



5
6
7
# File 'lib/bench/runner.rb', line 5

def initialize(defn)
  @defn = defn
end

Instance Method Details

- (Object) each(&reporter)

Alf contract



42
43
44
# File 'lib/bench/runner.rb', line 42

def each(&reporter)
  self.dup._each(&reporter)
end

- (Object) range_over(range, name, &block)



22
23
24
25
26
# File 'lib/bench/runner.rb', line 22

def range_over(range, name, &block)
  range.each do |value|
    with(name => value){ block.call(value) }
  end
end

- (Object) report(hash = {}, &block)



33
34
35
36
37
38
# File 'lib/bench/runner.rb', line 33

def report(hash = {}, &block)
  hash = {:bench => hash} unless hash.is_a?(Hash)
  with(hash) {
    with(:tms => Bench.measure{block.call}){ output }
  }
end

- (Object) variation_point(name, value, &proc)



28
29
30
31
# File 'lib/bench/runner.rb', line 28

def variation_point(name, value, &proc)
  h = {name => value}
  with(h, &proc)
end

- (Object) with(hash)

DSL



11
12
13
14
15
16
17
18
19
20
# File 'lib/bench/runner.rb', line 11

def with(hash)
  if block_given?
    @stack << @stack.last.merge(hash)
    res = yield
    @stack.pop
    res
  else
    @stack.last.merge!(hash)
  end  
end