Last active
May 29, 2019 10:48
-
-
Save adamphillips/5865777 to your computer and use it in GitHub Desktop.
A quick and dirty url benchmarking script. Needs a chmod +x. Alternatively just run it with ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Used to perform multiple requests of urls for benchmarking | |
# | |
# @example | |
# # Requests the url 3 times outputting times for each | |
# ./benchmark_url 3 http://my.url.com | |
# ruby benchmark_url 3 http://my.url.com | |
# | |
# # Requests each url 5 times outputting times for each | |
# ./benchmark_url 5 http://my.url.com http://my.url2.com | |
# ruby benchmark_url 5 http://my.url.com http://my.url2.com | |
require 'benchmark' | |
require 'net/http' | |
require 'uri' | |
numtimes = ARGV.shift | |
urls = ARGV | |
urls.each do |u| | |
total = 0 | |
puts u | |
puts '=' * u.length | |
(1..numtimes.to_i).each do |n| | |
time = Benchmark.realtime {Net::HTTP.get_response(URI.parse(u))} | |
puts "#{u} - #{n} : #{time}s" | |
total += time | |
end | |
puts '=' * u.length | |
puts "Average for #{u} : #{(total / numtimes.to_i).round(4)}s" | |
puts "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment