class BigBench::Benchmark::Benchmark

Attributes

duration[RW]
fragments[RW]
is_running[RW]
name[RW]
runs[RW]
start[RW]
threads[RW]
tracker[RW]
uri[RW]

Public Class Methods

new(name, url, options, &block) click to toggle source

Initizalizes a new benchmark

# File lib/bigbench/benchmark.rb, line 35
def initialize(name, url, options, &block)
  @name, @uri, @tracker, @is_running, @runs = name, URI(url), Tracker::Tracker.new, false, 0
  @threads  = options[:threads]   || BigBench.config.threads
  @duration = options[:duration]  || BigBench.config.duration
  @fragments = BigBench::Fragment.parse(self, &block)
end

Public Instance Methods

is_running?() click to toggle source

Returns if this benchmark is currently running

# File lib/bigbench/benchmark.rb, line 67
def is_running?
  @is_running
end
run!() click to toggle source

Execute this benchmark

# File lib/bigbench/benchmark.rb, line 43
def run!
  
  # Setup timer
  timer = Thread.new{ sleep(@duration); @is_running = false }
  @start, @is_running = Time.now, true
  
  # Benchmark loop
  @running_threads = []
  @threads.times do
    @running_threads << Thread.new do
      while is_running? do
        Net::HTTP.start(uri.host, uri.port) do |http|
          @fragments.each{ |fragment| fragment.run!(http) }
        end
      end
    end
  end
  
  # Stop execution
  @running_threads.each { |thread| thread.join }
  @runs += 1
end