/* See timefunc.h */ /* Last edited on 2001-09-30 18:46:15 by stolfi */ #include "timefunc.h" #include #include #include int timefunc_do_empty(int ntimes); void time_func ( char *title, int (*func) (int ntimes), int ntimes ) { double start, stop, tare; int actual_ntimes; /* Time an empty loop, to discount... */ start = now(); (void) timefunc_do_empty(ntimes); stop = now(); tare = stop-start; /* Now time the function itself: */ start = now(); actual_ntimes = func(ntimes); stop = now(); fprintf(stderr, "times for %s:\n", title); fprintf(stderr, " total iterations = %d\n", actual_ntimes); fprintf(stderr, " start clock (ms) = %.0f\n", start/1000.0); fprintf(stderr, " stop clock (ms) = %.0f\n", stop/1000.0); fprintf(stderr, " total time (ms) = %.0f\n", (stop-start)/1000.0); fprintf(stderr, " overhead (ms) = %.0f (%.1f%%)\n", tare/1000.0, 100*tare/(stop-start+0.00001) ); fprintf(stderr, " average us/call = %.3f\n", (stop-start-tare)/((double)actual_ntimes) ); } int timefunc_do_empty(int ntimes) { int i; for (i=0; i