From: Robert Klemme Date: 2011-09-26T18:33:25+09:00 Subject: Re: problems with Benchmark on ruby 1.8.4 (rhe 5.3) On Mon, Sep 26, 2011 at 6:32 AM, Russell F. wrote: > Yes I know the version is ancient -- I'm stuck with it for various > boring reasons we need not go into here. > > I have a ruby program that processes logs on an hourly basis for lots > (hundreds) of machines.  I want to find out which machines are taking > all the time so I reached for benchmark: > >    if  $options['time-hosts'] >        $log_store.traverse do | dir_name, mach| >           t = Benchmark.measure(mach) { process_host( dir_name, mach ) > } >           puts " >>>#{t}<<<" >        end >    end > > the puts never gets executed. > > I also did a version with bm() do |x| > immediately after the first if and x.report(mach) {} > > produced machinename1:       machine2:   ...... > > I have managed to get measure to behave in simple irb trial.   Is there > anything that I must not do in the code that is being benchmarked? Dunno. You could try to find out where it hangs with set_trace_func lambda {|*a| $stderr.puts a.inspect} But if you don't find a solution to your problem you can just use Time.now, e.g. t0 = Time.now # work t1 = Time.now duration = t1 - t0 # Float You can even wrap that in a simple method def time t0 = Time.now yield t1 = Time.now t1 - t0 # Float end dur = time { sleep 1.3 } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/