Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I accurately benchmark the time it takes to load a model?

I want to benchmark the time it takes to load a module (a find_by_id(234) call).

Also, how can I track the time it takes to load a page, I know I get this information when I run rails server, but this is in debug mode, I want production speed benchmarks, possible?

like image 437
Blankman Avatar asked Apr 07 '11 02:04

Blankman


2 Answers

For a quick check, I would highly recommend checking out Benchmark.

An example would be:

require "benchmark"

time = Benchmark.measure do
  a.find_by_id(234)
end
puts time

However for production level benchmarking, I would check out New Relic. They offer unbelievable benchmarking on nearly everything you could think of.

They have a free developer mode here :

http://support.newrelic.com/kb/docs/developer-mode

like image 101
Mike Lewis Avatar answered Oct 30 '22 10:10

Mike Lewis


You can use this gem: https://github.com/igorkasyanchuk/benchmark_methods

No more code like this:

t = Time.now
user.calculate_report
puts Time.now - t

Now you can do:

benchmark :calculate_report # in class

And just call your method

user.calculate_report
like image 38
Igor Kasyanchuk Avatar answered Oct 30 '22 11:10

Igor Kasyanchuk