Solved

TIME command

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
UNiX Script filesystem space usage 19 68
auto mounter on solaris 1 52
Best way to split and output to csv in bash 2 61
Bash Script to Analyze Oracle Schemas 11 83
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

910 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