Class: BigBench::Benchmark::Looper

Inherits:
Object
  • Object
show all
Defined in:
lib/bigbench/benchmark/looper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(benchmark) ⇒ Looper

Returns a new instance of Looper.



9
10
11
12
# 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

Instance Attribute Details

#benchmarkObject

Returns the value of attribute benchmark.



6
7
8
# File 'lib/bigbench/benchmark/looper.rb', line 6

def benchmark
  @benchmark
end

#loopsObject

Returns the value of attribute loops.



7
8
9
# File 'lib/bigbench/benchmark/looper.rb', line 7

def loops
  @loops
end

Instance Method Details

#loop!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_fragmentObject



37
38
39
# File 'lib/bigbench/benchmark/looper.rb', line 37

def next_fragment
  @fragments.resume
end