Class: BigBench::Benchmark::Looper
- Inherits:
-
Object
- Object
- BigBench::Benchmark::Looper
- Defined in:
- lib/bigbench/benchmark/looper.rb
Instance Attribute Summary collapse
-
#benchmark ⇒ Object
Returns the value of attribute benchmark.
-
#loops ⇒ Object
Returns the value of attribute loops.
Instance Method Summary collapse
-
#initialize(benchmark) ⇒ Looper
constructor
A new instance of Looper.
- #loop! ⇒ Object
- #next_fragment ⇒ Object
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
#benchmark ⇒ Object
Returns the value of attribute benchmark.
6 7 8 |
# File 'lib/bigbench/benchmark/looper.rb', line 6 def benchmark @benchmark end |
#loops ⇒ Object
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_fragment ⇒ Object
37 38 39 |
# File 'lib/bigbench/benchmark/looper.rb', line 37 def next_fragment @fragments.resume end |