Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
timingTest.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// timingTest.cpp : Defines the entry point for the console application.
20//
21
22#include "stdafx.h"
23#define WIN32_LEAN_AND_MEAN
24#include <windows.h>
25#include <mmsystem.h>
26#include <iostream.h>
27#include <string.h>
28
29double s_ticksPerSec = 0.0f;
30double s_ticksPerMSec = 0.0f;
31char buffer[1024];
32
33//-------------------------------------------------------------------------------------------------
34void GetPrecisionTimer(INT64* t)
35{
36 // CPUID is needed to force serialization of any previous instructions.
37 __asm
38 {
39 RDTSC
40 MOV ECX,[t]
41 MOV [ECX], EAX
42 MOV [ECX+4], EDX
43 }
44}
45
46//-------------------------------------------------------------------------------------------------
48{
49 __int64 totalTime = 0;
50 INT64 TotalTicks = 0;
51 static int TESTS = 10;
52
53 cout << "Starting tests..." << flush;
54
55 for (int i = 0; i < TESTS; ++i)
56 {
57 int TimeStart;
58 int TimeStop;
59 INT64 StartTicks;
60 INT64 EndTicks;
61
62 TimeStart = timeGetTime();
63 GetPrecisionTimer(&StartTicks);
64 for(;;)
65 {
66 TimeStop = timeGetTime();
67 if ((TimeStop - TimeStart) > 1000)
68 {
69 GetPrecisionTimer(&EndTicks);
70 break;
71 }
72 }
73
74 TotalTicks += (EndTicks - StartTicks);
75
76 totalTime += (TimeStop - TimeStart);
77 }
78
79 cout << "...completed" << endl;
80 s_ticksPerMSec = 1.0 * TotalTicks / totalTime;
81 s_ticksPerSec = s_ticksPerMSec * 1000.0f;
82
83 sprintf(buffer, "Ticks per sec: %.2f\n", s_ticksPerSec);
84 cout << buffer;
85 sprintf(buffer, "Ticks per msec: %.2f\n", s_ticksPerMSec);
86 cout << buffer;
87}
88
89int main(int argc, char* argv[])
90{
91 INT64 startTime, endTime, totalTime = 0;
93 FILE *out = fopen("output.txt", "w");
94 cout << "Beginning Looping tests: " << endl;
95
96 const int TESTCOUNT = 60;
97
98 while (1) {
99 for (int i = 0; i < TESTCOUNT; ++i) {
100 GetPrecisionTimer(&startTime);
101 Sleep(5);
102 GetPrecisionTimer(&endTime);
103 totalTime += (endTime - startTime);
104 }
105
106 double avgPerFrame = 1.0 * totalTime / TESTCOUNT;
107
108 sprintf(buffer, "%.8f,\t", avgPerFrame / s_ticksPerMSec );
109 fwrite(buffer, strlen(buffer), 1, out);
110 fflush(out);
111 cout << buffer << endl;
112 totalTime = 0;
113 }
114 fclose(out);
115
116 return 0;
117}
118
void main(void)
Definition test1.cpp:47
void RDTSC(void)
Definition mpu.cpp:127
double s_ticksPerSec
double s_ticksPerMSec
void InitPrecisionTimer()
void GetPrecisionTimer(INT64 *t)