Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created September 6, 2011 18:01
Show Gist options
  • Save evanphx/1198447 to your computer and use it in GitHub Desktop.
Save evanphx/1198447 to your computer and use it in GitHub Desktop.
require 'socket'
profile = false
if ARGV.first == "-p"
profile = true
ARGV.shift
end
port = ARGV.shift
count = ARGV.shift
all = count.to_i.times.map do
s = TCPSocket.new "0.0.0.0", port.to_i
start = Time.now
s << "GET /perf/index HTTP/1.0\r\n"
s << "Host: 0.0.0.0:3001\r\n"
s << "X-Profile: true\r\n" if profile
s << "User-Agent: ApacheBench/2.3\r\n"
s << "Accept: */*\r\n\r\n"
s.read
Time.now.to_f - start.to_f
end
sum = all.inject { |a,i| a + i}
mean = sum / count.to_i.to_f
puts "mean: #{mean}"
puts "r/s: #{1.0 / mean}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment