time: real, user and sys

Posted on 2004-08-23
Medium Priority
Last Modified: 2008-01-09

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?

Question by:hankknight
  • 2
  • 2

Accepted Solution

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.

Expert Comment

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.

Expert Comment

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 ;-)

Expert Comment

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...

Expert Comment

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.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
This article explains how to use the rsync command to create backups and sync data across hosts. Rsync is a very useful command that is often used to copy data, make backups, migrate hosts, and bridge the gap between site staging and production envi…
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.
Suggested Courses

624 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