home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / DSPDTST.C < prev    next >
C/C++ Source or Header  |  1992-01-16  |  4KB  |  137 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, Watcom, or ZTC */
  13.  
  14.  #ifndef __ZTC__
  15.   #include <graph.h>
  16.  
  17.   #ifndef __WATCOMC__
  18.    #define LOGFILE "dspdtst.msc"
  19.  
  20.    #define MK_FP(seg,off) ((void far *)(((dword)(seg)<<16)|(off)))
  21.    #define cputs(s) _outtext((char _far *)(s))
  22.   #else
  23.    #define LOGFILE "dspdtst.wc"
  24.   #endif  /* not Watcom   */
  25.  
  26.   #define gotoxy(col,row) _settextposition(row,col)
  27.  
  28.  #else   /* if ZTC       */
  29.   #define LOGFILE "dspdtst.ztc"
  30.  
  31.   #include <disp.h>
  32.  
  33.   #define cputs(s) disp_puts(s "\n")
  34.   #define cprintf(s) disp_printf(s "\n")
  35.   #define gotoxy(col,row) asm(0xb2,col-1,0xb6,row-1,0xb7,0,0xb4,2,0xcd,0x10)
  36.  
  37.  #endif  /* if ZTC       */
  38. #else
  39.  #define LOGFILE "dspdtst.tc"
  40. #endif  /* if TC        */
  41.  
  42. dword far *bios_time = MK_FP(0x0040,0x006C);
  43. dword time1,time2,time3,time4,time5,time6;
  44.  
  45. void main(void)
  46. {
  47.         int i;
  48.         FILE *log = stdout, *nulfile;
  49.  
  50. #ifdef __ZTC__
  51.         disp_open();
  52. #endif
  53.         nulfile = fopen("NUL", "w");
  54.         time1 = *bios_time;
  55.         for(i = 1; i < 1000; i++)
  56.         {
  57.                 gotoxy(10,5);
  58.                 puts("puts      test.");
  59.                 puts("this is the second line.\n");
  60.         }
  61.         time1 = *bios_time - time1;
  62.         time2 = *bios_time;
  63.         for(i = 1; i < 1000; i++)
  64.         {
  65.                 gotoxy(10,5);
  66.                 printf("printf    test.\n");
  67.                 printf("this is the second line.\n");
  68.         }
  69.         time2 = *bios_time - time2;
  70.         time3 = *bios_time;
  71.         for(i = 1; i < 1000; i++)
  72.         {
  73. #ifdef __ZTC__
  74.                 disp_move(4,9);
  75.                 cputs("d_puts    test.");
  76. #else
  77.                 gotoxy(10,5);
  78.  #if defined(M_I86) && !defined(__WATCOMC__)
  79.                 cputs("_outtext  test.\r\n");
  80.  #else
  81.                 cputs("cputs     test.\r\n");
  82.  #endif
  83. #endif
  84.                 cputs("this is the second line.");
  85.         }
  86.         time3 = *bios_time - time3;
  87.         time4 = *bios_time;
  88.         for(i = 1; i < 1000; i++)
  89.         {
  90. #ifdef __ZTC__
  91.                 disp_move(4,9);
  92.                 cprintf("d_printf  test.");
  93. #else
  94.                 gotoxy(10,5);
  95.                 cprintf("cprintf   test.\r\n");
  96. #endif
  97.                 cprintf("this is the second line.");
  98.         }
  99.         time4 = *bios_time - time4;
  100.         time5 = *bios_time;
  101.         for(i = 1; i < 1000; i++)
  102.         {
  103.                 fputs("fputs     test.\n", nulfile);
  104.                 fputs("this is the second line.\n", nulfile);
  105.         }
  106.         time5 = *bios_time - time5;
  107.         time6 = *bios_time;
  108.         for(i = 1; i < 1000; i++)
  109.         {
  110.                 fprintf(nulfile, "fprintf   test.\n");
  111.                 fprintf(nulfile, "this is the second line.\n");
  112.         }
  113.         time6 = *bios_time - time6;
  114.  
  115. #ifdef __ZTC__
  116.         disp_close();
  117. #endif
  118.         log = fopen(LOGFILE, "w");
  119.         fputs("Times for 1000 iterations:\n\n", log);
  120.         fprintf(log, "puts     %10.3f seconds\n", (double)time1 * .054945);
  121.         fprintf(log, "printf   %10.3f seconds\n", (double)time2 * .054945);
  122. #ifndef __ZTC__
  123.  #if defined(M_I86) && !defined(__WATCOMC__)
  124.         fprintf(log, "_outtext %10.3f seconds\n", (double)time3 * .054945);
  125.  #else
  126.         fprintf(log, "cputs    %10.3f seconds\n", (double)time3 * .054945);
  127.  #endif
  128.         fprintf(log, "cprintf  %10.3f seconds\n", (double)time4 * .054945);
  129. #else
  130.         fprintf(log, "d_puts   %10.3f seconds\n", (double)time3 * .054945);
  131.         fprintf(log, "d_printf %10.3f seconds\n", (double)time4 * .054945);
  132. #endif
  133.         fprintf(log, "fputs    %10.3f seconds\n", (double)time5 * .054945);
  134.         fprintf(log, "fprintf  %10.3f seconds\n", (double)time6 * .054945);
  135.         fclose(log);
  136. }
  137.