speed up bench add param for iterations
This commit is contained in:
parent
1915f292ad
commit
b8184d8b92
|
@ -5,6 +5,7 @@ require "optparse"
|
|||
|
||||
@include_env = false
|
||||
@result_file = nil
|
||||
@iterations = 500
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: ruby bench.rb [options]"
|
||||
|
||||
|
@ -14,6 +15,9 @@ opts = OptionParser.new do |o|
|
|||
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!
|
||||
|
||||
|
@ -25,9 +29,7 @@ begin
|
|||
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 = {}
|
||||
|
@ -86,11 +88,10 @@ if @include_env
|
|||
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
|
||||
|
@ -124,9 +125,9 @@ api_key = `bundle exec rake api_key:get`.split("\n")[-1]
|
|||
|
||||
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|
|
||||
|
|
Loading…
Reference in New Issue