From: Dave Thomas Date: 2001-01-17T07:36:29+09:00 Subject: [ruby-talk:9399] Re: Spiffy timing method anyone? Jim Freeze writes: > I noticed that the Time class supports microsecionds. I am interested in > how Rubyites perform timing sutdies on blocks of code. Goto-san's 'benchmark' library is your friend. For full benchmarks, you can do things like require 'benchmark' include Benchmark bm(10) do |tester| tester.report("times") { 100000.times {|i| i+i } } tester.report("upto") { 1.upto(100000) {|i| i+i } } end which produces: user system total real times 0.240000 0.000000 0.240000 ( 0.245942) upto 0.250000 0.000000 0.250000 ( 0.247145) For one-off timings, there's also require 'benchmark' include Benchmark timing = measure { 100000.times {|i| i+i } } p timing.to_a #=> ["", 0.27, 0.0, 0.0, 0.0, 0.2487230301] Regards Dave