#include <unistd.h> #include <time.h> #include <stdio.h> #define WAIT_TIME 7 /* time to wait in the delay loop */ #define tick_secs(ticks, clock_ticks) ((double)(ticks)/ \ (double)(clock_ticks)) int main() { long start_time; /* time at which the timed section started */ long end_time; /* time at which the timed section ended */ long total_time; /* total time for the timed section */ long calibration; /* time spent within the rtclock() function */ long clock_ticks; /* number of clock ticks per second */ clock_ticks = sysconf(_SC_CLK_TCK); (void) rtclock(); start_time = rtclock(); end_time = rtclock(); calibration = end_time - start_time; start_time = rtclock(); (void) sleep(WAIT_TIME); /* timed portion of the code */ end_time = rtclock(); total_time = end_time - start_time - calibration; (void) printf("%s%f\t%s%ld\n\t%s%ld\t\t%s%ld\n", "time (secs): ", tick_secs(total_time, clock_ticks), "time (ticks): ", total_time, "calibration (ticks): ", calibration, "ticks per second: ", clock_ticks); return(0); }
Generated with CERN WebMaker