Solved

time: real, user and sys

Posted on 2004-08-23
5
10,802 Views
Last Modified: 2008-01-09
Hello.

I used "time" to compare several different sh scripts that do the same thing, to find out which was the fastest.

The results look something like this:

        real    1m30.700s
        user    0m49.510s
        sys     0m16.610s


What are the three different times, and what do they mean?
And when deciding which one to use, which "time" (real, user, or sys) should be compared to choose the lowest?

Thanks!
0
Comment
Question by:hankknight
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
willy134 earned 500 total points
ID: 11874640
You are probably more interested in total time.  However the user time and system time are intersting to look at.

The user time is the time the cpu spent performing user related tasks (your script)

the system time is the time the cpu spent doing system related tasks (the kernel...)


However in the end it really does take real time to finish.  Choose that one to pick the script to use.

If you are going to further develop the script the other times may be of more use to you.
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 11874666
There is actually only 2 different results:

real and user/sys

real is the time that elapsed from the start of the script until it finished.

user/sys is the time that the script used on the processor, divided in user-space and kernel-space.

The second result is the most comparable between different solutions. The real time will vary wildly with the system load.

For your purpose it is probably ok to add the 2 times together and just look at the total. Generally it is considered as desirable to spend as little time as possible in kernel space, so if total times are equal you can compare those.
0
 
LVL 2

Expert Comment

by:_kiew
ID: 11874704
If you read time(1) man page, you'll see that :
* the "real" time is the elapsed (wall clock) time used  by  the process
* the "user" time is the total number of CPU-seconds that the process used directly (in user mode)
* the "system" time is the total number of CPU-seconds used by the system on behalf  of  the  process  (in  kernel mode)

To compare your scripts speed, I think "user"+"sys" is a good choice, "real" time can (should) be more than the sum of these two,
because it includes time spent running and attending other processes.

And remember, "man" is our friend ;-)
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 11875367
Watchout Hankknight,

willy134 is stating that total time is an accurate measure. IT IS NOT! It only shows the elapsed time since teh script started, not the actual processing power needed. You can do a simple test by doing teh following:
time ping -c 3 -i 1 localhost

and  after that
time ping -c 3 -i 5 localhost

You will see that real time is way longer for the second command ( about 15 seconds where the first is only 3), however  the user and sys times are almost identical. As it should be because both commands do the same: send 3 packets.

I don't mind the points, it's just that the  answer is not correct...
0
 
LVL 5

Expert Comment

by:willy134
ID: 11875929
if the total time is --always-- on a certain program it is definitely and accurate measurement.  IF my computer runs under an average load all day the total time to run a program is all that matters to me.  I don't care if one program has a little less user time.  The total time is what I (the user) really care about.   Total time take into account all the paging of memory and disk necessary sys/user time do not.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now