Forum: Ruby How to understand the Benchmark result

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
51224bdd17878b3b19e8987e9bb336a2?d=identicon&s=25 Deepak Gole (Guest)
on 2008-12-02 13:00
(Received via mailing list)
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)*
*
Cb6bbc826cd7d9238a2fae344958f7ec?d=identicon&s=25 Sandor Szücs (Guest)
on 2008-12-02 14:27
(Received via mailing list)
On 02.12.2008, at 12:54, Deepak Gole 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
Bb6ecee0238ef2461bef3416722b35c5?d=identicon&s=25 pat eyler (Guest)
on 2008-12-03 15:05
(Received via mailing list)
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:

http://on-ruby.blogspot.com/2008/12/benchmarking-m...

Have a look.
This topic is locked and can not be replied to.