Measure response time for a HTTP request using Ruby

Squadrons picture Squadrons · Mar 27, 2013 · Viewed 9.8k times · Source

I'm building a small website for personal use to test an API my company makes. My boss wants a website where we can enter a website, request a form using GET or POST, and the number of times to send the request. He wants the request logged, the time per request, and the average time for all the requests.

Is there a way to measure the response time for a GET or POST request using Ruby?

I looked through the Net::HTTP library, but didn't see anything that returned the time taken.

Are there any websites that already do this? They'd need to have a GUI so non-techies can use it. If not, I was planning on having a simple form that runs a script, writes the ouput of that script to a text file or spreadsheet, and then sends it to the user.

Any other suggestions? (A nice AJAX looking interface might work nicely, but would probably require database storage. At 10000 requests per run, that could get hefty.

Answer

ireddick picture ireddick · Mar 28, 2013

As mentioned in the comments, ruby has a benchmark module

require "benchmark"

time = Benchmark.measure do
  #requests
end