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