Solved

TIME command

Posted on 1998-08-26
2
325 Views
Last Modified: 2010-04-21
When running a program within the time command three values are given: REAL, USER and SYSTEM. For benchmarking purposes, which value do I use if I want execution time irrespective of machine overhead?
0
Comment
Question by:rsorrent
[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 Comments
 
LVL 3

Accepted Solution

by:
elfie earned 50 total points
ID: 2006796
Real time is the differnce between the starting time and ending time.(elapsed time)

User time is the cpu time spend in 'user' coding.
system time is the time spend in executing 'system' code.

If you run on a clean system (no overhead) you will see that adding user and system time will give you (approximately) the real time.

If you have no 'clean' system, just take user and system time, and it will give you a good indication for benchmarking.

On a heavy loaded system, 'system' time can increase due to a higher number of page faults, swap out/in, and other interruptions.

Always keep in mind that there is always a difference between a first run and the next executions of a program. Executing a program a second time, mostly means thah the program is still i memory, and thus requires less startup time.
0
 
LVL 2

Expert Comment

by:JYoungman
ID: 2006797
Any of the three, still, depending on what you mean by "machine overhead".  Perhaps if I explain the three times, you'll be able to choose the one you want.

When a program runs, it uses the CPU for up to 100% of the time it is running.  If it spends most of its time waiting for data from disks or terminals, or waiting for disk writes to complete, it may only use 1% of the CPU's time.  In this case, REAL time may be one second (the program took 1s to finish) but (USER+SYSTEM) may only be 0.01s.

USER time is time your program spends actually using the CPU to execute its own instructions.  SYSTEM time is time spent by the kernel using the CPU on behalf of that program, to fulfil requests that the program makes.   Here is an example program:-

[james@noisy james]$ cat us.c
#include <sys/time.h>
#include <unistd.h>

int main()
  {
  int i;
  struct timeval tv;
  struct  timezone tz;
  for (i=0; i<1000000; ++i)
    gettimeofday(&tv, &tz);
  return 0;
  }
[james@noisy james]$ make CFLAGS="-O2" LDLIBS= us
cc -O2  -g  us.c   -o us
[james@noisy james]$ time ./us
0.60user 1.80system 0:02.41elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (60major+7minor)pagefaults 0swaps

Here we see that most of the execution time was spent using the CPU, but 1.8s of that (75%) was SYSTEM (i.e. kernel) time.

If you're benchmarking a database, wall-clock time taken to complete a task may be the best measurement.   On the other hand, for a compute-intensive task, USER or (USER+SYSTEM) may be the best measures.


0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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.:
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…

705 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