mysql,Linux,HighPerformance,ruby on Rails

2009年11月11日星期三

在搞清楚&block的用法时看到的bechmack方法

来源:http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html
以后在测试性能时可能会用到.记在此.
Benchmark.bmbm(10) do |rpt|
rpt.report("foo") do
n.times {foo('Sidu', 'Ponnappa'){|name| "Hello #{name}"}}
end

rpt.report("bar") do
n.times {bar('Sidu', 'Ponnappa'){|name| "Hello #{name}"}}
end

rpt.report("ooga") do
n.times {
the_block = lambda {|name| "Hello #{name}"}
ooga('Sidu', 'Ponnappa', the_block)
}
end
end

显示结果:
Starting benchmark

Rehearsal ---------------------------------------------
foo 0.781000 0.000000 0.781000 ( 0.782000)
bar 1.406000 0.000000 1.406000 ( 1.406000)
ooga 1.438000 0.016000 1.454000 ( 1.453000)
------------------------------------ total: 3.641000sec

user system total real
foo 0.782000 0.000000 0.782000 ( 0.781000)
bar 1.375000 0.015000 1.390000 ( 1.406000)
ooga 1.453000 0.032000 1.485000 ( 1.485000)





没有评论:

发表评论