Solved

time: real, user and sys

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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 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.:

759 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

21 Experts available now in Live!

Get 1:1 Help Now