home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n02 / turtle.exe / TIMING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-22  |  2.2 KB  |  96 lines

  1. /******************************************************************
  2.  *                                                                *
  3.  * TIMING.C    -  simple non-rigorous benchmark for               *
  4.  *                286 | DOS Extender                              *
  5.  *                                                                *
  6.  * Compile with:                                                  *
  7.  * CL -AL -Lp -G2 -Ox timing.c graphp.obj llibpe.lib graphics.lib *
  8.  * (protected mode)                                               *
  9.  * OR:                                                            *
  10.  * CL -AL -G2 -Ox timing.c graphics.lib                           *
  11.  * (real mode)                                                    *
  12.  *                                                                *
  13.  ******************************************************************/
  14. #include <stdio.h>
  15. #include <graph.h>
  16. #include <time.h>
  17.  
  18. #define time_mark time_it(0)
  19. #define time_done time_it(1)
  20.  
  21. main()
  22.   {
  23.   printf("Timing graphics operations\n");
  24.   time_mark;
  25.   gtest();
  26.   time_done;
  27.   printf("Timing file operations\n");
  28.   time_mark;
  29.   ftest();
  30.   time_done;
  31.   exit(0);
  32.   }
  33.  
  34. /* Function to mark times */
  35. int time_it(int flag)
  36.   {
  37.   static clock_t sttime;
  38.   unsigned s;
  39.   if (!flag)
  40.     {
  41.     sttime=clock();
  42.     }
  43.   else
  44.     {
  45.     s=(clock()-sttime)/CLK_TCK;
  46.     printf("Elapsed time: %d seconds\n",s);
  47.     }
  48.   return 0;
  49.   }
  50.  
  51.  
  52. /* Graphics test -- must have VGA */
  53. int gtest()
  54.   {
  55.   int i,x,y;
  56.   _setvideomode(_MRES256COLOR);
  57.   for (i=1;i<11;i++)
  58.     {
  59.     _setcolor(i);
  60.     for (y=0;y<199;y++)
  61.       for (x=0;x<319;x++)
  62.         _setpixel(x,y);
  63.     }
  64.   _setvideomode(_DEFAULTMODE);
  65.   return 0;
  66.   }
  67.  
  68.  
  69. /* File test -- assumes 320K free on current drive */
  70. char filedata[64000];
  71.  
  72. int ftest()
  73.   {
  74.   FILE *tfile;
  75.   int i,j;
  76.   for (j=0;j<10;j++)
  77.     {
  78.     tfile=fopen("~~TIMING.~@~","w");
  79.     if (!tfile)
  80.       {
  81.       perror("TIMING");
  82.       exit(1);
  83.       }
  84.     for (i=0;i<5;i++)
  85.       fwrite(filedata,sizeof(filedata),1,tfile);
  86.     if (fclose(tfile))
  87.       {
  88.       perror("TIMING");
  89.       }
  90.     unlink("~~TIMING.~@~");
  91.     }
  92.   return 0;
  93.   }
  94.  
  95.  
  96.