?
Solved

time: real, user and sys

Posted on 2004-08-23
5
Medium Priority
?
10,894 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
willy134 earned 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 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