# How to understand the Benchmark result

**URL:** <https://www.ruby-forum.com/t/how-to-understand-the-benchmark-result/154632>\
**Category:** Ruby\
**Created:** [December 2, 2008, 1:00pm UTC](https://www.ruby-forum.com/t/how-to-understand-the-benchmark-result/154632 "2008-12-02T13:00:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Deepak\_G](https://www.ruby-forum.com/u/Deepak_G)\
**Post date:** [December 2, 2008, 1:00pm UTC](https://www.ruby-forum.com/t/how-to-understand-the-benchmark-result/154632/1 "2008-12-02T13:00:30Z")

</div>

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)_  
\*

---

<div class="post-metadata">

**Author:** ![Deepak\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Deepak\_G](https://www.ruby-forum.com/u/Deepak_G)\
**Post date:** [December 2, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/how-to-understand-the-benchmark-result/154632/2 "2008-12-02T14:27:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deepak\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Deepak\_G](https://www.ruby-forum.com/u/Deepak_G)\
**Post date:** [December 3, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/how-to-understand-the-benchmark-result/154632/3 "2008-12-03T15:05:38Z")

</div>

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:

> **[Benchmarking Makes it Better](http://on-ruby.blogspot.com/2008/12/benchmarking-makes-it-better.html)**
>
> This blog post is pulled from the Profiling and Optimizing Ruby tutorial I wrote for IBM DeveloperWorks a couple of years ago. If you'd li...

Have a look.
