如何准确地确定加载模型所需的时间?

Bla*_*man 6 benchmarking ruby-on-rails

我想对加载模块所花费的时间进行基准测试(find_by_id(234)调用).

另外,我如何跟踪加载页面所需的时间,我知道在运行rails服务器时我得到了这些信息,但这是在调试模式下,我想要生产速度基准,可能吗?

Mik*_*wis 26

为了快速检查,我强烈建议您查看Benchmark.

一个例子是:

require "benchmark"

time = Benchmark.measure do
  a.find_by_id(234)
end
puts time
Run Code Online (Sandbox Code Playgroud)

但是对于生产水平基准测试,我会查看New Relic.它们几乎可以为您提供所有想法,提供令人难以置信的基准测试.

他们有一个免费的开发者模式:

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