28 May 2014

This week I have to do some benchmarking and I found out rails provides a library which can help accomplish it easily.

http://apidock.com/rails/ActiveSupport/Benchmarkable/benchmark

Refer to the example code, which can do benchmark for the given process and write into log file.

But my requirements is to get the benchmarks and do some extra calculation. So I read the source code and finally I did something like:

milliseconds = Benchmark.ms do
   ........
end

It will return the time taken by the process, then I can do anything I want with it.