class BigBench::Benchmark::Looper

Attributes

benchmark[RW]
loops[RW]

Public Class Methods

new(benchmark) click to toggle source
# File lib/bigbench/benchmark/looper.rb, line 9
def initialize(benchmark)
  @benchmark, @loops = benchmark, 0
  @fragments = Fiber.new { @benchmark.fragments.cycle{ |fragment| Fiber.yield(fragment) } }
end

Public Instance Methods

loop!() click to toggle source
# File lib/bigbench/benchmark/looper.rb, line 14
def loop!
  return unless @benchmark.is_running?
  @loops += 1
  
  # Start next fragment
  fragment = next_fragment
  start = Time.now
  http = fragment.run!
  
  # Success
  http.callback do |http|
    fragment.track!(start, Time.now, http)
    loop!
  end
  
  # Error
  http.errback do |http|
    fragment.track!(start, Time.now, http)
    loop!
  end
  
end
next_fragment() click to toggle source
# File lib/bigbench/benchmark/looper.rb, line 37
def next_fragment
  @fragments.resume
end