You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

  1. /****************************
  2. * High-level timing wrappers
  3. ****************************/
  4. #include <stdio.h>
  5. #include "fsecs.h"
  6. #include "fcyc.h"
  7. #include "clock.h"
  8. #include "ftimer.h"
  9. #include "config.h"
  10. static double Mhz; /* estimated CPU clock frequency */
  11. extern int verbose; /* -v option in mdriver.c */
  12. /*
  13. * init_fsecs - initialize the timing package
  14. */
  15. void init_fsecs(void)
  16. {
  17. Mhz = 0; /* keep gcc -Wall happy */
  18. #if USE_FCYC
  19. if (verbose)
  20. printf("Measuring performance with a cycle counter.\n");
  21. /* set key parameters for the fcyc package */
  22. set_fcyc_maxsamples(20);
  23. set_fcyc_clear_cache(1);
  24. set_fcyc_compensate(1);
  25. set_fcyc_epsilon(0.01);
  26. set_fcyc_k(3);
  27. Mhz = mhz(verbose > 0);
  28. #elif USE_ITIMER
  29. if (verbose)
  30. printf("Measuring performance with the interval timer.\n");
  31. #elif USE_GETTOD
  32. if (verbose)
  33. printf("Measuring performance with gettimeofday().\n");
  34. #endif
  35. }
  36. /*
  37. * fsecs - Return the running time of a function f (in seconds)
  38. */
  39. double fsecs(fsecs_test_funct f, void *argp)
  40. {
  41. #if USE_FCYC
  42. double cycles = fcyc(f, argp);
  43. return cycles/(Mhz*1e6);
  44. #elif USE_ITIMER
  45. return ftimer_itimer(f, argp, 10);
  46. #elif USE_GETTOD
  47. return ftimer_gettod(f, argp, 10);
  48. #endif
  49. }