Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created August 5, 2017 18:43
Show Gist options
  • Save brand-it/ad858d4c5e7ff1dc26cc99bb4fa7cc4b to your computer and use it in GitHub Desktop.
Save brand-it/ad858d4c5e7ff1dc26cc99bb4fa7cc4b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark'
require 'net/http'
require 'optparse'
options = { total_execute_time: 300, uri: 'https://gitlab.com' }
OptionParser.new do |opts|
opts.banner = "Usage: curl_gitlab [options]"
opts.on('-t', '--total-execute-time SECONDS', 'How long you would like to run this command for') do |t|
options[:total_execute_time] = t.to_i
end
opts.on('-h', '--host URI', 'Check this to call a different host') do |t|
options[:host] = t.to_i
end
end.parse!
started_at = Time.now.to_i
stop_at = started_at + options[:total_execute_time]
uri = URI(options[:uri])
reports = []
Benchmark.bm do |x|
while Time.now.to_i <= stop_at
reports << x.report do
Net::HTTP.get(uri)
end
end
end
puts "Avarage Response time in seconds"
puts (reports.inject(0.0) { |sum, report| sum + report.real } / reports.size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment