TX Library Help – Version: 00173a, Revision: 174
 ALL  Windows graphics in a sandbox

TestSpeed.cpp

См. документацию.
00001 //{=========================================================================== 
00011 //              $Copyright: (C) Ded (Ilya Dedinsky, http://txlib.ru) <mail@txlib.ru> $
00012 //}===========================================================================
00013 
00014 #include "TXLib.h"
00015 
00016 #if !defined (_TX_VER) || (_TX_VER < 0x172a0000)
00017 #error Must use TXLib.h version >= 1.72 to compile this. -- Ded
00018 #endif
00019 
00020 //============================================================================
00021 
00022 double TrySleep (int ms);
00023 
00024 //----------------------------------------------------------------------------
00025 
00026 int main()
00027     {
00028     txCreateWindow (800, 600);
00029 
00030     LARGE_INTEGER f = {};
00031     QueryPerformanceFrequency (&f);
00032     double freq = f.QuadPart / 1E6;
00033 
00034     double perf = txQueryPerformance();
00035 
00036     printf ("\n" "QueryPerformanceFrequency(): %.2f GHz\n", freq);
00037     printf (     "txQueryPerformance(): %.2f\n", perf);
00038 
00039     if (perf < 1) perf = 1;
00040 
00041     int x = 10, y = 10,
00042        vx = (int) (10/perf), vy = (int) (10/perf);
00043 
00044     txBegin();
00045 
00046     while (!GetAsyncKeyState (VK_ESCAPE))
00047         {
00048         txSetFillColor (TX_BLACK);
00049         txClear();
00050 
00051         txSetFillColor (TX_WHITE);
00052         txCircle (x, y, 10);
00053 
00054         printf ("  \r" "Minimum effective txSleep (%.2f)", TrySleep (1));
00055 
00056         x += vx;
00057         y += vy;
00058 
00059         if (x < 0 || x > txGetExtentX()) { x -= vx; vx *= -1; }
00060         if (y < 0 || y > txGetExtentY()) { y -= vy; vy *= -1; }
00061         }
00062 
00063     return 0;
00064     }
00065 
00066 //----------------------------------------------------------------------------
00067 
00068 double TrySleep (int ms)
00069     {
00070     static LARGE_INTEGER f = {};
00071     if (!f.QuadPart) QueryPerformanceFrequency (&f);
00072 
00073     LARGE_INTEGER t0 = {};
00074     QueryPerformanceCounter (&t0);
00075 
00076     txSleep (ms);
00077 
00078     LARGE_INTEGER t1 = {};
00079     QueryPerformanceCounter (&t1);
00080 
00081     double time = 1E3 * (t1.QuadPart - t0.QuadPart) / f.QuadPart;
00082 
00083     static double avr[100] = {};
00084     static unsigned n = 0;
00085 
00086     avr [n++ % SIZEARR (avr)] = time;
00087     if  (n   < SIZEARR (avr)) return time;
00088 
00089     time = 0;
00090     for (unsigned i = 0; i < SIZEARR (avr); i++) time += avr[i];
00091     return time / SIZEARR (avr);
00092     }
00093 
00094 
00095 
00096 
00097