home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / examples / profile / test.c < prev   
Encoding:
C/C++ Source or Header  |  1996-12-24  |  1.1 KB  |  86 lines

  1. /* Example program for demonstrating profiling */
  2.  
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <sprof.h>
  6. #include <dos.h>
  7.  
  8. int factor = 10;
  9.  
  10. #define CALL(func,x) for(i=0; i<(x); i++) (func)();
  11.  
  12. #define DELAY {__chkabort(); for(i=0; i<100*factor; i++);}
  13.  
  14. static void f100static(void)
  15. {
  16.    int i;
  17.    DELAY;
  18. }
  19.  
  20. void f100(void)
  21. {
  22.    int i;
  23.    DELAY;
  24. }
  25.  
  26. void f100b(void)
  27. {
  28.    int i;
  29.    DELAY;
  30. }
  31.  
  32. void f100c(void)
  33. {
  34.    int i;
  35.    DELAY;
  36. }
  37.  
  38. void f200(void)
  39. {
  40.    int i;
  41.    DELAY;
  42. }
  43.  
  44. void f300(void)
  45. {
  46.    int i;
  47.    DELAY;
  48. }
  49.  
  50. void f30x100(void)
  51. {
  52.    int i;
  53.    CALL(f100b,100);
  54. }
  55.  
  56. void f100x3(void)
  57. {
  58.    f100c();
  59.    f100c();
  60.    f100c();
  61. }
  62.  
  63. int main(int argc, char *argv[])
  64. {
  65.    int i;
  66.    if(argc > 1)
  67.    {
  68.       stcd_i(argv[1], &factor);
  69.       if(factor <= 0) factor = 10;
  70.       PROFILE_OFF();
  71.       /* These statements doesn't count when profiling with SPROF */
  72.       printf("Using delay factor of %d\n", factor);
  73.       printf("Hit RETURN to continue: ");
  74.       getch();
  75.       printf("Continuing...\n");
  76.       PROFILE_ON();
  77.    }
  78.    CALL(f100static, 100);
  79.    CALL(f100,100);
  80.    CALL(f200,200);
  81.    CALL(f300,300);
  82.    CALL(f30x100,30);
  83.    CALL(f100x3,100);
  84.    return(0);
  85. }
  86.