On 02.12.2008, at 12:54, Deepak Gole wrote:
>
> I had ran 2 methods against Benchmark and  got following output. But =20=

> didn't
> understand which method is faster and what is "elapsed real time".
>
> *1st Method benchmark result
> *user CPU time   system CPU time
> 0.235000           0.015000                0.250000 (  6.797000)
>
>
> *2nd Method benchmark result
> *user CPU time   system CPU time
> 18.906000          0.250000              19.156000 ( 19.250000)*
> *


The first method is faster because it didn't consume as much CPU time
as the second.
IIRC the different times mean the following:
The first method took 0.235 seconds of user land CPU time (x86 speak: =20=

Ring3)
The second method took 0.015 seconds of kernel land CPU time (x86 =20
speak: Ring0)
The third time is the total time which is user land + kernel land CPU =20=

time
The fourth time is the time which was really taken.

Maybe an interesting example to understand the difference between =20
total and real
is:

# Runs a benchmark with blocking I/O and wait some time, before =20
writing some data
# through the pipe.
irb(main):020:0> Benchmark.bm do |x|
irb(main):021:1*  x.report { File.open("/tmp/myfifo", 'r') {|f| =20
f.read(4)}}
irb(main):022:1> end
       user     system      total        real
   0.000000   0.000000   0.000000 (  6.760203)
=3D> true
$ echo bla > /tmp/myfifo  # at another shell


# Write some data through the pipe and then run a benchmark with =20
blocking I/O.
$ echo bla > /tmp/myfifo
irb(main):023:0> Benchmark.bm do |x|
irb(main):024:1*  x.report { File.open("/tmp/myfifo", 'r') {|f| =20
f.read(4)}}
irb(main):026:1* end
       user     system      total        real
   0.000000   0.000000   0.000000 (  0.000236)


hth. regards, Sandor Sz=FCcs
--