home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DSPDTST.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  4KB  |  129 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Compiler I/O benchmarks
  5. **  public domain by Dave Knapp & Bob Stout
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <conio.h>
  10. #include <dos.h>
  11. #include "errors.h"           /* For cant()                             */
  12. #include "sniptype.h"         /* For DWORD                              */
  13. #include "extkword.h"         /* For FAR                                */
  14. #include "scrnmacs.h"         /* For portable screen I/O                */
  15. #include "dvidport.h"         /* For portable direct video I/O          */
  16.  
  17. #ifndef ITERATIONS
  18.  #define ITERATIONS 5000
  19. #endif
  20.  
  21. #ifdef M_I86      /* Identifier for MSC, QC, Watcom, or ZTC */
  22.  #ifndef __ZTC__
  23.   #include <graph.h>
  24.   #ifndef __WATCOMC__
  25.    #ifdef _MSC_VER
  26.     #define LOGFILE "dspdtst.msc"
  27.    #else
  28.     #define LOGFILE "dspdtst.qc"
  29.    #endif
  30.   #else
  31.    #define LOGFILE "dspdtst.wc"
  32.   #endif    /* not Watcom   */
  33.  #else      /* if ZTC       */
  34.   #include <disp.h>
  35.   #ifdef __SC__
  36.    #define LOGFILE "dspdtst.sc"
  37.   #else
  38.    #define LOGFILE "dspdtst.ztc"
  39.   #endif
  40.  #endif     /* if ZTC       */
  41. #else       /* must be Borland or Mix     */
  42.  #ifdef __TURBOC__
  43.   #ifdef __BORLANDC__
  44.    #define LOGFILE "dspdtst.bc"
  45.   #else
  46.    #define LOGFILE "dspdtst.tc"
  47.   #endif
  48.  #endif
  49.  #ifdef __POWERC
  50.   #define LOGFILE "dspdtst.pc"
  51.  #endif
  52. #endif
  53.  
  54. #ifndef LOGFILE
  55.  #error Unrecognized compiler
  56. #endif
  57.  
  58. DWORD FAR *bios_time = (DWORD FAR *)(0x0040006cL);
  59. DWORD time1, time2, time3, time4, time5, time6;
  60.  
  61. main()
  62. {
  63.         int i;
  64.         FILE *log = stdout, *nulfile;
  65.  
  66.         ClrScrn(BG_(BLACK_)+GRAY_);
  67.         nulfile = cant("NUL", "w");
  68.         time1 = *bios_time;
  69.         for(i = 1; i < ITERATIONS; i++)
  70.         {
  71.                 gotoxy(10,5);
  72.                 puts("puts      test.");
  73.                 puts("this is the second line.\n");
  74.         }
  75.         time1 = *bios_time - time1;
  76.         time2 = *bios_time;
  77.         for(i = 1; i < ITERATIONS; i++)
  78.         {
  79.                 gotoxy(10,8);
  80.                 printf("printf    test.\n");
  81.                 printf("this is the second line.\n");
  82.         }
  83.         time2 = *bios_time - time2;
  84.         dvid_open();
  85.         time3 = *bios_time;
  86.         for(i = 1; i < ITERATIONS; i++)
  87.         {
  88.                 gotoxy(10,11);
  89.                 cputs("cputs     test.\r\n");
  90.                 cputs("this is the second line.\r\n");
  91.         }
  92.         time3 = *bios_time - time3;
  93.         time4 = *bios_time;
  94.         for(i = 1; i < ITERATIONS; i++)
  95.         {
  96.                 gotoxy(10,14);
  97.                 cprintf("cprintf   test.\r\n");
  98.                 cprintf("this is the second line.\r\n");
  99.         }
  100.         time4 = *bios_time - time4;
  101.         dvid_close();
  102.         time5 = *bios_time;
  103.         for(i = 1; i < ITERATIONS; i++)
  104.         {
  105.                 fputs("fputs     test.\n", nulfile);
  106.                 fputs("this is the second line.\n", nulfile);
  107.         }
  108.         time5 = *bios_time - time5;
  109.         time6 = *bios_time;
  110.         for(i = 1; i < ITERATIONS; i++)
  111.         {
  112.                 fprintf(nulfile, "fprintf   test.\n");
  113.                 fprintf(nulfile, "this is the second line.\n");
  114.         }
  115.         time6 = *bios_time - time6;
  116.  
  117.         log = cant(LOGFILE, "w");
  118.         fprintf(log, "Times for %d iterations:\n\n", ITERATIONS);
  119.         fprintf(log, "puts     %10.3f seconds\n", (double)time1 * .054945);
  120.         fprintf(log, "printf   %10.3f seconds\n", (double)time2 * .054945);
  121.         fprintf(log, "cputs    %10.3f seconds\n", (double)time3 * .054945);
  122.         fprintf(log, "cprintf  %10.3f seconds\n", (double)time4 * .054945);
  123.         fprintf(log, "fputs    %10.3f seconds\n", (double)time5 * .054945);
  124.         fprintf(log, "fprintf  %10.3f seconds\n", (double)time6 * .054945);
  125.         fclose(log);
  126.         printf("\nDone - results are in %s\n", LOGFILE);
  127.         return 0;
  128. }
  129.