/* see timefunc.h */ /****************************************************************************/ /* (C) Copyright 1993 Universidade Estadual de Campinas (UNICAMP) */ /* Campinas, SP, Brazil */ /* */ /* This file can be freely distributed, modified, and used for any */ /* non-commercial purpose, provided that this copyright and authorship */ /* notice be included in any copy or derived version of this file. */ /* */ /* DISCLAIMER: This software is offered ``as is'', without any guarantee */ /* as to fitness for any particular purpose. Neither the copyright */ /* holder nor the authors or their employers can be held responsible for */ /* any damages that may result from its use. */ /****************************************************************************/ #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 = %.2f\n", (stop-start-tare)/((double)actual_ntimes) ); } int timefunc_do_empty(int ntimes) { int i; for (i=0; i