home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1995 November / PCWK1195.iso / inne / dos / programo / pmw120.exe / EXAMPLES.ZIP / EXAMPLE2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.5 KB  |  104 lines

  1. /*****************************************************************************
  2.  
  3.   The original purpose of this test program was to show that floating point
  4. calculations do in fact work under PMODE/W. However, during development we
  5. found that floating point under DOS/4GW was EXTREMELY slow. Run this on a
  6. PC without an FPU or disable the FPU on your 486. Try it under DOS/4GW and
  7. under PMODE/W and notice the speed difference. If the timing values are too
  8. close to be able to tell, try changing the variable "count" to something
  9. larger.
  10.  
  11.   For those who think this is not accurate because of the cprintf () that is
  12. in there, if you remove the cprintf () from the innermost loop you will find
  13. that the results are pretty much the same as far as the ratio of the speeds
  14. goes.
  15.  
  16. *****************************************************************************/
  17.  
  18. #include <conio.h>
  19. #include <math.h>
  20. #include <time.h>
  21. #include <dos.h>
  22.  
  23. #define M_PI 3.141592654
  24.  
  25. #pragma aux mode3 =\
  26.         "mov ax,3",\
  27.         "int 10h",\
  28.         modify [ax];
  29.  
  30. void main (void)
  31. {
  32.   clock_t tstart, tend;
  33.  
  34.   double  dtemp;
  35.   int     x, line, count = 10000;
  36.  
  37.   mode3 ();
  38.  
  39.   printf ("This program will test several Watcom C floating point functions\n"
  40.           "for speed. Each function will be executed %d times. Depending\n"
  41.           "on the speed of your system, this may take a while. This test is\n"
  42.           "only of use on systems WITHOUT a floating point unit.\n", count);
  43.  
  44.   line = 6;
  45.   gotoxy (0, line);
  46.  
  47.   tstart = clock ();
  48.   cprintf ("pow () Test");
  49.  
  50.   for (x=0; x<count; x++)
  51.   {
  52.     gotoxy (30, line);
  53.     dtemp = pow (1234, 56);
  54.     cprintf ("%-6u", x);
  55.   }
  56.  
  57.   tend = clock ();
  58.   gotoxy (40, line);
  59.   cprintf ("%.4f Seconds\r\n", (float)(tend-tstart) / (float)CLOCKS_PER_SEC);
  60.   line ++;
  61.  
  62.   tstart = clock ();
  63.   cprintf ("sin () Test");
  64.  
  65.   for(x=0; x<count; x++)
  66.   {
  67.     gotoxy (30, line);
  68.     dtemp = sin (123456789);
  69.     cprintf ("%-6u", x);
  70.   }
  71.  
  72.   tend = clock ();
  73.   gotoxy (40, line);
  74.   cprintf ("%.4f Seconds\r\n", (float)(tend-tstart) / (float)CLOCKS_PER_SEC);
  75.   line ++;
  76.  
  77.   tstart = clock ();
  78.   cprintf ("sqrt () Test");
  79.  
  80.   for(x=0; x<count; x++)
  81.   {
  82.     gotoxy (30, line);
  83.     dtemp = sqrt (123456789);
  84.     cprintf ("%-6u", x);
  85.   }
  86.  
  87.   tend = clock ();
  88.   gotoxy (40, line);
  89.   cprintf ("%.4f Seconds\r\n", (float)(tend-tstart) / (float)CLOCKS_PER_SEC);
  90. }
  91.  
  92. void gotoxy (char gx, char gy)
  93. {
  94.   union REGS r;
  95.  
  96.   r.h.ah = 2;
  97.   r.h.bh = 0;
  98.   r.h.dl = gx;
  99.   r.h.dh = gy;
  100.  
  101.   int386 (0x10, &r, &r);
  102. }
  103.  
  104.