On 09/29/2009 05:07 PM, Marvin G=FClker wrote:
> I think you're looking for the benchmark library (in Ruby's stdlib). To=
=20
> quote from the docs:
> (...)
>      This report shows the user CPU time, system CPU time, the sum of
>      the user and system CPU times, and the elapsed real time. The unit=

>      of time is seconds.
> (...)
>          require 'benchmark'
>=20
>          n =3D 50000
>          Benchmark.bm(7) do |x|
>            x.report("for:")   { for i in 1..n; a =3D "1"; end }
>            x.report("times:") { n.times do   ; a =3D "1"; end }
>            x.report("upto:")  { 1.upto(n) do ; a =3D "1"; end }
>          end
>=20
>      The result:
>=20
>                          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)
>=20
> Marvin

There is also Benchmark.times (process times so far) and=20
Benchmark.measure (timing of a particular operation):

irb(main):019:0> Benchmark.times
=3D> #<struct Struct::Tms utime=3D0.11, stime=3D0.06, cutime=3D0.0, cstim=
e=3D0.0>

irb(main):020:0> Benchmark.measure { 10.times do end }
=3D> #<Benchmark::Tms:0x91f53c0 @label=3D"", @real=3D1.02519989013672e-05=
,=20
@cstime=3D0.0, @cutime=3D0.0, @stime=3D0.0, @utime=3D0.0, @total=3D0.0>
irb(main):021:0> Benchmark.measure "foo" { 10.times do end }
=3D> #<Benchmark::Tms:0x91e5650 @label=3D"foo", @real=3D1.00135803222656e=
-05,=20
@cstime=3D0.0, @cutime=3D0.0, @stime=3D0.0, @utime=3D0.0, @total=3D0.0>
irb(main):022:0>

Kind regards

	robert


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