Benchmark question

J

Joe Van Dyk

irb(main):015:0> Benchmark.measure { 1000000.times { |i| i + 1 } }
=3D>=20
#<Benchmark::Tms:0x400fa914 @cutime=3D0.0, @label=3D"", @stime=3D0.0,
@real=3D0.514808893203735, @utime=3D4.95, @cstime=3D0.0, @total=3D4.95>

Why is user time bigger than real time? I'm confused by the
relationship between these numbers.
 
J

Joe Van Dyk

ruby 1.8.2, compiled on Redhat 9.

What version of Ruby are you on?

Here's what I see:

mohit@reddwarf log $ irb
irb(main):001:0> require 'benchmark'
=3D> true
irb(main):002:0> Benchmark.measure{ 1000000.times{ |i| i + 1 } }
=3D> #<Benchmark::Tms:0xb7d57984 @cutime=3D0.0, @label=3D"", @stime=3D0= 0,
@real=3D0.589663028717041, @utime=3D0.59, @cstime=3D0.0, @total=3D0.59>
irb(main):004:0> quit
mohit@reddwarf log $ ruby -v
ruby 1.8.2 (2004-12-25) [i686-linux]
mohit@reddwarf log $

Real time on my results are also lower than user time. But this may be
a floating-point precision thing.

I think your version of Benchmark is expressing "real time" in
seconds, and the others in centi-seconds.

Mohit.

irb(main):015:0> Benchmark.measure { 1000000.times { |i| i + 1 } }
=3D>
#<Benchmark::Tms:0x400fa914 @cutime=3D0.0, @label=3D"", @stime=3D0.0,
@real=3D0.514808893203735, @utime=3D4.95, @cstime=3D0.0, @total=3D4.9= 5>

Why is user time bigger than real time? I'm confused by the
relationship between these numbers.
=20
=20
--
Mohit Muthanna [mohit (at) muthanna (uhuh) com]
"There are 10 types of people. Those who understand binary, and those
who don't."
=20
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top