question on timing results

Matthew Saltzman mjs at ces.clemson.edu
Thu Jun 16 14:20:33 UTC 2005


On Thu, 16 Jun 2005, Globe Trotter wrote:

> Hi,
>
> Here is an example cooked up just to show how it works. Only done with utime
> and stime, but can be extended to the other two in exactly the same way. But I
> wonder, which should be used? As per the manpage for times(2), the function
> reports the value of four times in four fields. 1)  The tms_utime field
> contains the CPU time spent executing  instructions of  the  calling  process.
> 2) The  tms_stime field contains the CPU time spent in the system while
> executing tasks on behalf of the calling process.  3) The  tms_cutime  field
> contains  the  sum of the tms_utime and  tms_cutime  values  for  all
> waited-for  terminated   children. 4) The tms_cstime  field contains the sum of
> the tms_stime and tms_cstime values for all waited-for terminated children.
>
> My programs go into an algorithm and do lots of things. Which times shoudl I
> use?  I don't understand all this much: I am considering using the tms_utime
> field, but I don't know if I should use that or the sum of the first two or all
> of them. Any suggestions: I guess I really don't know what all these
> different times mean.

It depends what you want to do with the results.

Usually, the time you care about for mathematical algorithm comparisons is 
the user time.  The system time is charged for the system parts of doing 
i/o, paging, task switching, etc.  If you're benchmarking a database 
transaction system, for example, you may care about both user and system 
times.

For example, when you issue an i/o call in your program, that call invokes 
a system service that actaully copies the bytes between the device and the 
buffer in memory where you get or put the data.  That system service's CPU 
time is charged to tms_stime.  If you type on the keyboard in another 
teriminal while your job is running, your job is suspended, the keyboard 
input handler is invoked, and the job in the other terminal gets a chance 
to handle the event.  Eventually, your job gets its turn again, and the 
sytem has to set it up and resume it.  The time the system spends stopping 
and resuming your job is charged to tms_stime.

If your code doesn't spawn child processes (if you aren't sure, then it's 
a pretty safe bet it doesn't), then tms_cutime and tms_cstime will be zero 
anyway.

>
> Many thanks and best wishes!
>
>
>
> __________________________________
> Discover Yahoo!
> Use Yahoo! to plan a weekend, have fun online and more. Check it out!
> http://discover.yahoo.com/

-- 
 		Matthew Saltzman

Clemson University Math Sciences
mjs AT clemson DOT edu
http://www.math.clemson.edu/~mjs




More information about the fedora-list mailing list