Solved

time: real, user and sys

Posted on 2004-08-23
5
10,855 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 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

724 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