Solved

TIME command

Posted on 1998-08-26
2
318 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
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 43
Bad Block Relocation for Synchronous GLVM AIX 7.1 2 73
Move nodes from one TSM to another. 3 77
Can I delete authorized_keys in FreeBSD 1 88
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

821 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