Question

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.

Was it helpful?

Solution

As mentioned in the comments, ruby has a benchmark module

require "benchmark"

time = Benchmark.measure do
  #requests
end

OTHER TIPS

Net::HTTP doesn't track response time, since it's not its job.

Before and after your request use Time.now to set start and end times:

start_time = Time.now
# ...do request...
elapsed_time = Time.now - start_time

If you want to average that, add the elapsed_time values together and divide by the number of tests:

total_time += elapsed_time
# ... do some stuff...
average_time = total_time / num_of_iterations

Time measures down to the micro-second, which should be plenty accurate for your needs.

You're on your own for the interface as that's an entirely different subject and would constitute a book.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top