home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / DSPDTST.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  4KB  |  150 lines

  1. /*
  2. **  Compiler I/O benchmarks
  3. **  public domain by Dave Knapp & Bob Stout
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <dos.h>
  9.  
  10. typedef unsigned long dword;
  11.  
  12. #ifdef M_I86      /* Identifier for MSC, QC, Watcom, or ZTC */
  13.  
  14.  #ifndef __ZTC__
  15.   #include <graph.h>
  16.  
  17.   #ifndef __WATCOMC__
  18.    #ifdef _MSC_VER
  19.     #define LOGFILE "dspdtst.msc"
  20.    #else
  21.     #define LOGFILE "dspdtst.qc"
  22.    #endif
  23.  
  24. //   #define MK_FP(seg,off) ((void far *)(((dword)(seg)<<16)|(off)))
  25.   #else
  26.    #define LOGFILE "dspdtst.wc"
  27.   #endif  /* not Watcom   */
  28.  
  29.   #define cputs(s) _outtext((char _far *)(s))
  30.   #define gotoxy(col,row) _settextposition(row,col)
  31.  
  32.  #else   /* if ZTC       */
  33.  
  34.   #include <disp.h>
  35.  
  36.   #define cputs(s) disp_puts(s "\n")
  37.   #define cprintf(s) disp_printf(s "\n")
  38.   #ifdef __SC__
  39.    #define LOGFILE "dspdtst.sc"
  40.    #define gotoxy(col,row) __emit__(0xb2,col-1,0xb6,row-1,0xb7,0,0xb4,2,0xcd,0x10)
  41.   #else
  42.    #define LOGFILE "dspdtst.ztc"
  43.    #define gotoxy(col,row) asm(0xb2,col-1,0xb6,row-1,0xb7,0,0xb4,2,0xcd,0x10)
  44.   #endif
  45.  
  46.  #endif  /* if ZTC       */
  47. #else
  48.  #ifdef __BORLANDC__
  49.   #define LOGFILE "dspdtst.bc"
  50.  #else
  51.   #define LOGFILE "dspdtst.tc"
  52.  #endif
  53. #endif  /* if TC        */
  54.  
  55. dword far *bios_time = (dword far *)(0x0040006c);
  56. dword time1,time2,time3,time4,time5,time6;
  57.  
  58. void main(void)
  59. {
  60.         int i;
  61.         FILE *log = stdout, *nulfile;
  62.  
  63. #ifdef __ZTC__
  64.         disp_open();
  65. #endif
  66.         nulfile = fopen("NUL", "w");
  67.         time1 = *bios_time;
  68.         for(i = 1; i < 1000; i++)
  69.         {
  70.                 gotoxy(10,5);
  71.                 puts("puts      test.");
  72.                 puts("this is the second line.\n");
  73.         }
  74.         time1 = *bios_time - time1;
  75.         time2 = *bios_time;
  76.         for(i = 1; i < 1000; i++)
  77.         {
  78.                 gotoxy(10,5);
  79.                 printf("printf    test.\n");
  80.                 printf("this is the second line.\n");
  81.         }
  82.         time2 = *bios_time - time2;
  83.         time3 = *bios_time;
  84.         for(i = 1; i < 1000; i++)
  85.         {
  86. #ifdef __ZTC__
  87.                 disp_move(4,9);
  88.                 cputs("d_puts    test.");
  89. #else
  90.                 gotoxy(10,5);
  91.  #if defined(M_I86) && !defined(__WATCOMC__)
  92.                 cputs("_outtext  test.\r\n");
  93.  #else
  94.                 cputs("cputs     test.\r\n");
  95.  #endif
  96. #endif
  97.                 cputs("this is the second line.");
  98.         }
  99.         time3 = *bios_time - time3;
  100.         time4 = *bios_time;
  101.         for(i = 1; i < 1000; i++)
  102.         {
  103. #ifdef __ZTC__
  104.                 disp_move(4,9);
  105.                 cprintf("d_printf  test.");
  106. #else
  107.                 gotoxy(10,5);
  108.                 cprintf("cprintf   test.\r\n");
  109. #endif
  110.                 cprintf("this is the second line.");
  111.         }
  112.         time4 = *bios_time - time4;
  113.         time5 = *bios_time;
  114.         for(i = 1; i < 1000; i++)
  115.         {
  116.                 fputs("fputs     test.\n", nulfile);
  117.                 fputs("this is the second line.\n", nulfile);
  118.         }
  119.         time5 = *bios_time - time5;
  120.         time6 = *bios_time;
  121.         for(i = 1; i < 1000; i++)
  122.         {
  123.                 fprintf(nulfile, "fprintf   test.\n");
  124.                 fprintf(nulfile, "this is the second line.\n");
  125.         }
  126.         time6 = *bios_time - time6;
  127.  
  128. #ifdef __ZTC__
  129.         disp_close();
  130. #endif
  131.         log = fopen(LOGFILE, "w");
  132.         fputs("Times for 1000 iterations:\n\n", log);
  133.         fprintf(log, "puts     %10.3f seconds\n", (double)time1 * .054945);
  134.         fprintf(log, "printf   %10.3f seconds\n", (double)time2 * .054945);
  135. #ifndef __ZTC__
  136.  #if defined(M_I86) && !defined(__WATCOMC__)
  137.         fprintf(log, "_outtext %10.3f seconds\n", (double)time3 * .054945);
  138.  #else
  139.         fprintf(log, "cputs    %10.3f seconds\n", (double)time3 * .054945);
  140.  #endif
  141.         fprintf(log, "cprintf  %10.3f seconds\n", (double)time4 * .054945);
  142. #else
  143.         fprintf(log, "d_puts   %10.3f seconds\n", (double)time3 * .054945);
  144.         fprintf(log, "d_printf %10.3f seconds\n", (double)time4 * .054945);
  145. #endif
  146.         fprintf(log, "fputs    %10.3f seconds\n", (double)time5 * .054945);
  147.         fprintf(log, "fprintf  %10.3f seconds\n", (double)time6 * .054945);
  148.         fclose(log);
  149. }
  150.