All that the C promises standard is that CLOCKS_PER_SEC
is a constant expression with type clock_t
, which must be an arithmetic type (can be an integer or a floating type).
(C99 7.23 Date and time <time.h>
)
I think that clock_t
usually long
, but I would not put in my life that I am right.
My usually faithful Harbison and Steele (3rd ed.) clock_t
using clock_t
to double
for use in your programs so that your code can work regardless of the actual clock_t
type (18.1 CLOCK, CLOCK_T, CLOCKS_PER_SEC, TIMES)
Here's how the clock
function can use ANSI C:
#include <time.h> clock_t start, finish, duration; start = clock(); process(); finish = clock(); printf("process() took %f seconds to execute\n", ((double) (finish - start)) / CLOCKS_PER_SEC );
Notice how the cast type double
allows clock_t
and CLOCKS_PER_SEC
be either a floating point or an integral.
You may be wondering if this will work for your purposes.
Michael burr
source share