How to understand the Benchmark result

Hi

I had ran 2 methods against Benchmark and got following output. But
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)

*

On 02.12.2008, at 12:54, Deepak G. wrote:

*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:
Ring3)
The second method took 0.015 seconds of kernel land CPU time (x86
speak: Ring0)
The third time is the total time which is user land + kernel land CPU
time
The fourth time is the time which was really taken.

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

Runs a benchmark with blocking I/O and wait some time, before

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|
f.read(4)}}
irb(main):022:1> end
user system total real
0.000000 0.000000 0.000000 ( 6.760203)
=> true
$ echo bla > /tmp/myfifo # at another shell

Write some data through the pipe and then run a benchmark with

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|
f.read(4)}}
irb(main):026:1* end
user system total real
0.000000 0.000000 0.000000 ( 0.000236)

hth. regards, Sandor
Szücs

Every once in a while somebody posts a question about benchmarking.
I’ve dusted off a primer on Benchmarking I wrote for IBM a couple of
years ago and posted it on my blog:

Have a look.