ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年7月24日 星期五
ruby benchmark
Benchmarking Makes it Better
require 'benchmark'
#The bm method provides basic interface to the benchmark method. It takes an optional label_width argument. Each method tested can have a label specified.
n = 5_000_000
Benchmark.bm(15) do |x|
x.report("for loop:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
end
# Model
Project.benchmark("Creating project") do
project = Project.create("name" => "stuff")
project.create_manager("name" => "David")
project.milestones << Milestone.find(:all)
end
# Controller
def process_projects
self.class.benchmark("Processing projects") do
Project.process(params[:project_ids])
Project.update_cached_projects
end
end
# View
<% benchmark("Showing projects partial") do %>
<%= render :partial => @projects %>
<% end %>
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言