On Mon, Sep 26, 2011 at 6:32 AM, Russell F. <russell.fulton / gmail.com> wrot=
e:
> 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. =A0I want to find out which machines are taking
> all the time so I reached for benchmark:
>
> =A0 =A0if =A0$options['time-hosts']
> =A0 =A0 =A0 =A0$log_store.traverse do | dir_name, mach|
> =A0 =A0 =A0 =A0 =A0 t =3D Benchmark.measure(mach) { process_host( dir_nam=
e, mach )
> }
> =A0 =A0 =A0 =A0 =A0 puts " >>>#{t}<<<"
> =A0 =A0 =A0 =A0end
> =A0 =A0end
>
> 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: =A0 =A0 =A0 machine2: =A0 ......
>
> I have managed to get measure to behave in simple irb trial. =A0 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 =3D Time.now
# work
t1 =3D Time.now
duration =3D t1 - t0 # Float

You can even wrap that in a simple method

def time
  t0 =3D Time.now
  yield
  t1 =3D Time.now
  t1 - t0 # Float
end

dur =3D time { sleep 1.3 }

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/