Program Runtime 
Author Message
 Program Runtime

Hi,

        I have written a C program which is compiled in unix environment. I want to know exactly how many CPU time this program takes to execute (not
including any CPU time that doing other process during this program's
execution). Could anyone tells me that either any command in the unix
shell or any C functions can do this? Thanks a lot.

Francis.



Tue, 04 Jan 2000 03:00:00 GMT  
 Program Runtime

Quote:
>Hi,

>    I have written a C program which is compiled in unix environment. I want to know exactly how many CPU time this program takes to execute (not
>including any CPU time that doing other process during this program's
>execution). Could anyone tells me that either any command in the unix
>shell or any C functions can do this? Thanks a lot.

>Francis.

The time command does excatly what you want : see man time

You can also use the wait3 syscall wich give the excecution time but also extra
informations useful for performance tuning.

Romain



Tue, 04 Jan 2000 03:00:00 GMT  
 Program Runtime

Quote:

>>Hi,

>>       I have written a C program which is compiled in unix environment. I
> want to know exactly how many CPU time this program takes to execute (not
>>including any CPU time that doing other process during this program's
>>execution). Could anyone tells me that either any command in the unix
>>shell or any C functions can do this? Thanks a lot.

>>Francis.

The clock() function measures CPU time and is a standard C library function.
Unix provides other functions and program timing commands if this doesn't
do exactly what you want but these should be discussed in
comp.unix.programmer.

To time a routine function you need to take the difference between 2 clock()
values e.g.

#include <time.h>

...

    clock_t start, end;

    start = clock();

    /* Put the code you want to time here, perhaps a function call */

    end = clock();

    printf("Time taken is %.2Lfs\n", (end - start)/(long double)CLOCKS_PER_SEC);

Quote:
>The time command does excatly what you want : see man time

No, time() measures wall-clock time, not CPU time.

--
-----------------------------------------


-----------------------------------------



Tue, 04 Jan 2000 03:00:00 GMT  
 Program Runtime

Quote:

>    I have written a C program which is compiled in unix environment. I want to know exactly how many CPU time this program takes to execute (not
> including any CPU time that doing other process during this program's
> execution). Could anyone tells me that either any command in the unix
> shell or any C functions can do this? Thanks a lot.

The clock function can be used to find the processor time since the
beginning of execution (by that process). There are CLOCKS_PER_SEC
clock ticks per second.

Note that this may not be very accurate, and may not even return any
useful information. Beyond this, you'll have to use an
implementation-specific facility.

More information on profiling can be found in the comp.lang.c FAQ,
which can be found at http://www.eskimo.com/~scs/C-faq/top.html and
ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/ .

--

            http://www.geocities.com/SiliconValley/Lakes/7537/



Sat, 08 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Microsoft Visual C++ runtime library Runtime error! - Program c:\cvi501\cvi.exe abnormal program termination

2. Turbo C program inconsistent runtime problems

3. Programming the ADO at runtime

4. program crashes at runtime

5. Runtime error! abnormal program termination

6. Program compiles fine but dies at runtime.

7. Getting program version at runtime.

8. Removing Program from Taskbar at *Runtime*

9. Getting program version at runtime.

10. Invisible at Runtime or Not Invisible at Runtime ?

11. Microsoft Visual C++ Runtime Library Runtime Error When Browsing in IE6

12. Microsoft Visual C++ Runtime Library Runtime Error When Browsing in IE6

 

 
Powered by phpBB® Forum Software