How can i measure the time taken by a method and the individual statements in that method in Ruby. If you see the below method i want to measure the total time taken by the meth
The simplest way:
require 'benchmark' def foo time = Benchmark.measure { code to test } puts time.real #or save it to logs end
Sample output:
2.2.3 :001 > foo 5.230000 0.020000 5.250000 ( 5.274806)
Values are: cpu time, system time, total and real elapsed time.
Source: ruby docs.