Shannon Fang <xrfang / hotmail.com> writes:

> yabm.rb:
> 
> class Yabm
>   def initialize
>     #@cp=[]
>     #@cp << [nil,Time.now]
      @cp = [nil, Time.now]
>   end
>   def report
>     total=@cp[@cp.length-1][1]-@cp[0][1]
>     caption="Time used: %0.2f sec."%total
>     #print "\n",caption,"\n"
      print "\ncaption\n"

> what is the meaning of "user time" and "system time"?
> Is it useful when doing benchmarking?

User time is the amount of CPU time spent within the user-space (your
program), and system time is the amount of CPU time spent within the
kernel (syscall calls). It is useful in determining where the program
is spending most of its time.

I/O bound programs are usually spend more time in syscall
calls, CPU bound programs in user-space. 

CPU bound programs can usually be improved by using a more efficient
algorithm and minimising side-activities (e.g. creation of
intermediate objects, etc). I/O bound programs can be improved by
optimising the I/O access pattern, and of course by upgrading the
I/O hardware if that is possible. 

## cpu bound program (looping 10e6 times)
jenny:~/tmp> /usr/bin/time ruby -e 'i=0;1000.times{1000.times{i += 1}}'
0.69user 0.00system 0:00.69elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (208major+118minor)pagefaults 0swaps

## i/o bound program (copying 100MB)
jenny:~/tmp> /usr/bin/time dd if=/dev/zero of=/tmp/vmlinuz bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes transferred in 1.004041 seconds (104435578 bytes/sec)
0.00user 1.02system 0:01.09elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (143major+19minor)pagefaults 0swaps

YS.