Class: B::Enchmark
Overview
B::Enchmark
Defined Under Namespace
Classes: Job
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from Ase
Instance Method Summary collapse
- #finish(job) ⇒ Object
-
#initialize(id, opts = {}) ⇒ Enchmark
constructor
A new instance of Enchmark.
- #job(id, opts = {}, &block) ⇒ Object
- #post_run ⇒ Object
- #start(job) ⇒ Object
Methods inherited from Ase
Constructor Details
#initialize(id, opts = {}) ⇒ Enchmark
Returns a new instance of Enchmark.
60 61 62 63 64 65 |
# File 'lib/b.rb', line 60 def initialize(id, opts={}) @opts = {:rounds => DEFAULT_ROUNDS, :compare => nil}.merge(opts) @parent = opts[:parent] @id, @rounds, @compare = id, opts[:rounds], opts[:compare] @buffer = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
45 46 47 |
# File 'lib/b.rb', line 45 def id @id end |
Instance Method Details
#finish(job) ⇒ Object
90 91 92 |
# File 'lib/b.rb', line 90 def finish(job) super if @compare.nil? end |
#job(id, opts = {}, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/b.rb', line 47 def job(id, opts={}, &block) if opts[:rounds] and @compare raise SanityViolation, "Can not override :rounds on job '#{id}' when comparing on :#{@compare}!" end if opts[:compare] raise SanityViolation, "Can not override :compare in a job ('#{id}')" end opts = @opts.merge(opts) (@children ||= []) << Job.new(self, id, opts, block) self end |
#post_run ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/b.rb', line 67 def post_run if @compare @buffer.sort! do |a,b| a.send(@compare) <=> b.send(@compare) end end @buffer.each_with_index do |job, i| if 0 == i job.x = 1.0 else job.x = job.send(@compare) / @buffer[0].send(@compare) end end until @buffer.empty? do @parent.start @buffer[0] @parent.finish @buffer.shift end end |
#start(job) ⇒ Object
86 87 88 |
# File 'lib/b.rb', line 86 def start(job) @compare.nil? ? super : @buffer << job end |