Measure and Benchmark Time for Ruby Methods

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)