Sha256: 95947d2f5c988ac9cd4eeedf673fad1b3e8cc3234c449092514d1615648b2a06

Contents?: true

Size: 904 Bytes

Versions: 5

Compression:

Stored size: 904 Bytes

Contents

module BigBench
  module Benchmark
    
    class Looper
      
      attr_accessor :benchmark
      attr_accessor :loops
      
      def initialize(benchmark)
        @benchmark, @loops = benchmark, 0
        @fragments = Fiber.new { @benchmark.fragments.cycle{ |fragment| Fiber.yield(fragment) } }
      end
      
      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
      
      def next_fragment
        @fragments.resume
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bigbench-0.0.6 lib/bigbench/benchmark/looper.rb
bigbench-0.0.5 lib/bigbench/benchmark/looper.rb
bigbench-0.0.4 lib/bigbench/benchmark/looper.rb
bigbench-0.0.3 lib/bigbench/benchmark/looper.rb
bigbench-0.0.2 lib/bigbench/benchmark/looper.rb