Reputation: 481
I am developing REST API tests in ruby using RSpec. I want to check the response time of each API call. Is there any method available in any Ruby gem which provides me the required information?
Upvotes: 0
Views: 866
Reputation: 1604
Disclaimer: This answer does not make use of RSpec for measuring the elapsed time.
You can use the Benchmark module provided by Ruby to measure the elapsed time for code execution.
To measure the real time taken by a block of code for execution:
require 'benchmark'
realtime = Benchmark.realtime do
# your code here
end
puts realtime # time taken in seconds
Check the documentation for further details about benchmarking.
Apart from the elapsed real time, it also lets you benchmark the user CPU time, system CPU time and the sum of the user and system CPU times.
Upvotes: 2