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
Returns if this benchmark is currently running
# File lib/bigbench/benchmark.rb, line 67 def is_running? @is_running end
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