Class: B::Enchmark::Job

Inherits:
Ase
  • Object
show all
Defined in:
lib/b.rb

Overview

B::Enchmark::Job

Constant Summary collapse

ATTRIBUTES =
[:group, :id, :rounds, :rate, :mean, :max, :min, :stddev, :x, :compare]

Instance Attribute Summary collapse

Attributes inherited from Ase

#opts

Instance Method Summary collapse

Methods inherited from Ase

#finish, #register, #start

Constructor Details

#initialize(parent, id, opts, block) ⇒ Job

Returns a new instance of Job.



101
102
103
104
105
# File 'lib/b.rb', line 101

def initialize(parent, id, opts, block)
  @opts = parent.opts.merge(opts)
  @parent, @block, @group, @id, @rounds, @compare = parent, block, parent.id, id, @opts[:rounds], @opts[:compare]
  @parent.register(self)
end

Instance Attribute Details

#x=(value) ⇒ Object (writeonly)

Sets the attribute x

Parameters:

  • value

    the value to set the attribute x to.



98
99
100
# File 'lib/b.rb', line 98

def x=(value)
  @x = value
end

Instance Method Details

#run!Object



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/b.rb', line 107

def run!
  tm = Hitimes::TimedMetric.new(nil)
  @parent.start self
  @opts[:rounds].times do
    tm.start
    @block.call
    tm.stop
  end
  @rate, @mean, @max, @min, @stddev = tm.rate, tm.mean, tm.max, tm.min, tm.stddev
  finish self
end

#to_hObject



119
120
121
122
123
124
# File 'lib/b.rb', line 119

def to_h
  ATTRIBUTES.reduce({}) { |m,e|
    m[e] = instance_variable_get('@'+e.to_s)
    m
  }
end