Re: speed of execution
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Fri, 19 May 2006 14:22:57 GMT
Nelu wrote:
pete wrote:
kavi wrote:
Hello friends,
Could any one tell the way of calculating the speed of c program
execution?
The clock function in <time.h> is for timing programs
or parts of programs.
{
clock_t start, stop;
start = clock();
while (start == clock()) {
;
}
start = clock();
/*
** Timed event goes here
*/
stop = clock();
return (double)(stop - start) / (double)CLOCKS_PER_SEC;
}
7.23.2.1 The clock function
Synopsis
[#1]
#include <time.h>
clock_t clock(void);
Description
[#2] The clock function determines the processor time used.
Returns
[#3] The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in
seconds, the value returned by the clock function should be
divided by the value of the macro CLOCKS_PER_SEC. If the
processor time used is not available or its value cannot be
represented, the function returns the value clock_t)-1.252)
____________________
252In order to measure the time spent in a program, the
clock function should be called at the start of the
program and its return value subtracted from the value
returned by subsequent calls.
From my man: "Note that the time can wrap around. On a 32 bit systemwhere CLOCKS_PER_SEC equals 1000000 this function will return the
same value approximately every 72 minutes".
If this is the case, I hope his program doesn't need 72 minutes to
complete.
In that case he's better off using a stop watch :-).
.... or maybe even a calendar.
Is clock affected by other processes in a multitasking OS, or does it
count only when the CPU works on the calling process?
"the implementation's best approximation
to the processor time used by the program"
.... which means
"only when the CPU works on the calling process"
except that
"other processes in a multitasking OS"
make the timing more complicated and possibly less accurate.
--
pete
.
- Follow-Ups:
- Re: speed of execution
- From: Nelu
- Re: speed of execution
- References:
- speed of execution
- From: kavi
- Re: speed of execution
- From: pete
- Re: speed of execution
- From: Nelu
- speed of execution
- Prev by Date: Re: Printing files every step
- Next by Date: Re: speed of execution
- Previous by thread: Re: speed of execution
- Next by thread: Re: speed of execution
- Index(es):
Relevant Pages
|