rails benchmark - oyaji's Blog

rails benchmark

oyaji posted @ 2011年1月28日 21:39 in 未分类 with tags rails benchmark , 1640 阅读

 

命令行工具


benckmark

#ruby script/performance/benchmarker 3 "Product.find :all"

执行3次Product.find :all, 输出结果中real列为实际运行所消耗的时间

profiler

#ruby script/performance/profiler "Product.find :all" 10

执行10次Product.find :all, 列出所有涉及到的类库的运行时间

 

测试用例


比如测试View中某段代码的执行时间,

 

<% benchmark("Showing projects partial") do %>
   <%= render :partial => @projects %>
<% end %>

 

Model中测试,

 

Project.benchmark("Creating project") do
  project = Project.create("name" => "stuff")
   project.create_manager("name" => "David")
   project.milestones << Milestone.find(:all)
end

 

日志


Rails生成的日志,

Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]

Rendering template within layouts/items

Rendering items/index

Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]

总的请求时间是5ms, View占了2ms, DB为0, 其他3ms为Controller占用,可以用shell来分析反应慢的请求

 

具体见这里


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee