class Phantomherd::Runner
Attributes
casper_script[R]
concurrency[R]
results[RW]
sample_count[R]
Public Class Methods
new(options)
click to toggle source
# File lib/phantomherd/runner.rb, line 10 def initialize(options) @sample_count = options[:sample_count] @concurrency = options[:concurrency] @casper_script = options[:casper_script] @results = [] end
Public Instance Methods
run()
click to toggle source
# File lib/phantomherd/runner.rb, line 17 def run requests = (1..sample_count.to_i).to_a EM.synchrony do EM::Synchrony::FiberIterator.new(requests, concurrency).each do |request| stime = Time.now out, status = EM::Synchrony.system("casperjs --ignore-ssl-errors=yes #{casper_script}") print "." @results << Time.now - stime end print "\n" EventMachine.stop end print_results end
Private Instance Methods
print_results()
click to toggle source
# File lib/phantomherd/runner.rb, line 34 def print_results avg = @results.inject{ |sum, el| sum + el}.to_f / @results.size puts "=" * 80 puts "phantomherd: #{casper_script} (#{sample_count} samples, #{concurrency} concurrent)" puts "=" * 80 puts "Average: #{avg.round(3)} sec" puts "Min: #{@results.min.round(3)} sec" puts "Max: #{@results.max.round(3)} sec" puts "=" * 80 puts "\nRaw results: \n#{@results.join(",")}" end