, (7) man- ( ).
clock_gettime (2), . CLOCK_MONOTONIC CLOCK_REALTIME double ( a struct timespec ).
uint16_t .
inline double double_gettime (clockid_t cid) {
struct timespec ts = {0,0};
clock_gettime(cid, &ts);
return (double)ts.tv_sec + 1.0e-9*ts.tv_nsec;
}
, fancier, , clock_gettime NAN, ! . , CLOCK_REALTIME .., (.. a struct timespec double)
,
double tstart = double_gettime(CLOCK_REALTIME);
some_long_computation();
double tend = double_gettime(CLOCK_REALTIME);
printf ("needed %f seconds to compute\n", tend-tstart);
. (3)