Skip to content

Commit

Permalink
speed up bench add param for iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Dec 30, 2013
1 parent 1915f29 commit b8184d8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions script/bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@include_env = false
@result_file = nil
@iterations = 500
opts = OptionParser.new do |o|
o.banner = "Usage: ruby bench.rb [options]"

Expand All @@ -14,6 +15,9 @@
o.on("-o", "--output [FILE]", "Output results to this file") do |f|
@result_file = f
end
o.on("-i", "--iterations [ITERATIONS]", "Number of iterations to run the bench for") do |i|
@iterations = i.to_i
end
end
opts.parse!

Expand All @@ -25,9 +29,7 @@ def run(command)
require 'facter'
rescue LoadError
run "gem install facter"
puts "just installed the facter gem, rerunning script"
exec("ruby " + [ File.absolute_path(__FILE__), __FILE__ ], *ARGV)
exit
require 'facter'
end

@timings = {}
Expand Down Expand Up @@ -86,11 +88,10 @@ def prereqs
ENV.delete "RUBY_FREE_MIN"
else
# clean env
puts "Running with default environment"
ENV.delete "RUBY_GC_MALLOC_LIMIT"
ENV.delete "RUBY_HEAP_SLOTS_GROWTH_FACTOR"
ENV.delete "RUBY_HEAP_MIN_SLOTS"
ENV.delete "RUBY_FREE_MIN"
puts "Running with the following custom environment"
%w{RUBY_GC_MALLOC_LIMIT RUBY_HEAP_MIN_SLOTS RUBY_FREE_MIN}.each do |w|
puts "#{w}: #{ENV[w]}"
end
end

def port_available? port
Expand Down Expand Up @@ -124,9 +125,9 @@ def port_available? port

def bench(path)
puts "Running apache bench warmup"
`ab -n 100 "http://127.0.0.1:#{@port}#{path}"`
`ab -n 10 "http://127.0.0.1:#{@port}#{path}"`
puts "Benchmarking #{path}"
`ab -n 500 -e tmp/ab.csv "http://127.0.0.1:#{@port}#{path}"`
`ab -n #{@iterations} -e tmp/ab.csv "http://127.0.0.1:#{@port}#{path}"`

percentiles = Hash[*[50, 75, 90, 99].zip([]).flatten]
CSV.foreach("tmp/ab.csv") do |percent, time|
Expand Down

0 comments on commit b8184d8

Please sign in to comment.