Programming Tutorials

(追記) (追記ここまで)

bm(label_width = 0, *labels) {|report| ...} in Ruby

By: Jeya in Ruby Tutorials on 2009年03月03日 [フレーム]

A simple interface to the benchmark method, bm is generates sequential reports with labels. The parameters have the same meaning as for benchmark.

 require 'benchmark'
 n = 50000
 Benchmark.bm(7) do |x|
 x.report("for:") { 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

Generates:

 user system total real
 for: 1.050000 0.000000 1.050000 ( 0.503462)
 times: 1.533333 0.016667 1.550000 ( 0.735473)
 upto: 1.500000 0.016667 1.516667 ( 0.711239)



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /