开发者

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

开发者 https://www.devze.com 2023-02-22 10:11 出处:网络
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 thi

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?


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


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


I would highly recommend that you read the Rails Guide on Performance Testing. It's a pretty good overview of what's available within rails. It's great if you want automated tests where you can make code changes and see instant results.

For production server benchmarking, New Relic probably does everything you'd want.

0

精彩评论

暂无评论...
验证码 换一张
取 消