Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit d098e1b

Browse files
committed
Fixes
1 parent 78cf7b6 commit d098e1b

File tree

1 file changed

+97
-18
lines changed

1 file changed

+97
-18
lines changed

ClassFromRTTI/ClassFromRTTI.cpp

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ typedef bool(__fastcall* fnIsTrue)(void* ecx, void* edx);
1818
typedef const char*(__fastcall* fnHelloWorld)(void* ecx, void* edx);
1919

2020
int main() {
21-
RTTI cRTTI1(true, true, true, true); // With caching + min iterations
22-
RTTI cRTTI2; // Without caching
21+
RTTI cRTTI1; // Default
22+
RTTI cRTTI2(false, true, true, true); // With caching
23+
RTTI cRTTI3(true); // With min iterations
24+
RTTI cRTTI4(true, true, true, true); // With cache and min iterations
2325

2426
HMODULE hTestDLL = LoadLibrary(TEXT("TestDLL.dll"));
2527
if (!hTestDLL) {
@@ -37,77 +39,154 @@ int main() {
3739
high_resolution_clock::time_point t1;
3840
high_resolution_clock::time_point t2;
3941

40-
for (unsigned char i = 0; i < 10; i++) {
42+
// Stage 1
43+
t1 = high_resolution_clock::now();
44+
for (unsigned char i = 0; i < 100; ++i) {
4145
if (unTestingRVA != cRTTI1.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
4246
printf("Error: Data error!\n");
4347
}
4448
}
4549
t2 = high_resolution_clock::now();
46-
printf("Bench (10 calls) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
50+
printf("Bench (100 calls)...............................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
4751

4852
t1 = high_resolution_clock::now();
49-
for (unsigned int i = 0; i < 10'000; i++) {
53+
for (unsigned short i = 0; i < 1'000; ++i) {
5054
if (unTestingRVA != cRTTI1.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
5155
printf("Error: Data error!\n");
5256
}
5357
}
5458
t2 = high_resolution_clock::now();
55-
printf("Bench (10 000 calls) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
59+
printf("Bench (1 000 calls).............................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
5660

5761
t1 = high_resolution_clock::now();
58-
for (unsigned int i = 0; i < 500'000; i++) {
62+
for (unsigned int i = 0; i < 10'000; ++i) {
5963
if (unTestingRVA != cRTTI1.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
6064
printf("Error: Data error!\n");
6165
}
6266
}
6367
t2 = high_resolution_clock::now();
64-
printf("Bench (500 000 calls) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
68+
printf("Bench (10 000 calls)............................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
6569

6670
t1 = high_resolution_clock::now();
67-
for (unsigned int i = 0; i < 1'000'000; i++) {
71+
for (unsigned int i = 0; i < 50'000; i++) {
6872
if (unTestingRVA != cRTTI1.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
6973
printf("Error: Data error!\n");
7074
}
7175
}
7276
t2 = high_resolution_clock::now();
73-
printf("Bench (1 000 000 calls) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
77+
printf("Bench (50 000 calls)............................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
7478

79+
// Stage 2
7580
t1 = high_resolution_clock::now();
76-
for (unsigned char i = 0; i < 10; i++) {
81+
for (unsigned char i = 0; i < 100; ++i) {
7782
if (unTestingRVA != cRTTI2.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
7883
printf("Error: Data error!\n");
7984
}
8085
}
8186
t2 = high_resolution_clock::now();
82-
printf("Bench (10 calls + NoCache + NoMinIterations) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
87+
printf("Bench (100 calls + Cache).......................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
8388

8489
t1 = high_resolution_clock::now();
85-
for (unsigned int i = 0; i < 10'000; i++) {
90+
for (unsigned short i = 0; i < 1'000; ++i) {
8691
if (unTestingRVA != cRTTI2.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
8792
printf("Error: Data error!\n");
8893
}
8994
}
9095
t2 = high_resolution_clock::now();
91-
printf("Bench (10 000 calls + NoCache + NoMinIterations) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
96+
printf("Bench (1 000 calls + Cache).....................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
9297

9398
t1 = high_resolution_clock::now();
94-
for (unsigned int i = 0; i < 50'000; i++) {
99+
for (unsigned int i = 0; i < 10'000; ++i) {
95100
if (unTestingRVA != cRTTI2.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
96101
printf("Error: Data error!\n");
97102
}
98103
}
99104
t2 = high_resolution_clock::now();
100-
printf("Bench (50 000 calls + NoCache + NoMinIterations) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
105+
printf("Bench (10 000 calls + Cache)....................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
101106

102107
t1 = high_resolution_clock::now();
103-
for (unsigned int i = 0; i < 100'000; i++) {
108+
for (unsigned int i = 0; i < 50'000; i++) {
104109
if (unTestingRVA != cRTTI2.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
105110
printf("Error: Data error!\n");
106111
}
107112
}
108113
t2 = high_resolution_clock::now();
109-
printf("Bench (100 000 calls + NoCache + NoMinIterations) = %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
114+
printf("Bench (50 000 calls + Cache)....................= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
115+
116+
// Stage 3
117+
t1 = high_resolution_clock::now();
118+
for (unsigned char i = 0; i < 100; ++i) {
119+
if (unTestingRVA != cRTTI3.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
120+
printf("Error: Data error!\n");
121+
}
122+
}
123+
t2 = high_resolution_clock::now();
124+
printf("Bench (100 calls + MinIterations)...............= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
125+
126+
t1 = high_resolution_clock::now();
127+
for (unsigned short i = 0; i < 1'000; ++i) {
128+
if (unTestingRVA != cRTTI3.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
129+
printf("Error: Data error!\n");
130+
}
131+
}
132+
t2 = high_resolution_clock::now();
133+
printf("Bench (1 000 calls + MinIterations).............= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
134+
135+
t1 = high_resolution_clock::now();
136+
for (unsigned int i = 0; i < 10'000; ++i) {
137+
if (unTestingRVA != cRTTI3.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
138+
printf("Error: Data error!\n");
139+
}
140+
}
141+
t2 = high_resolution_clock::now();
142+
printf("Bench (10 000 calls + MinIterations)............= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
143+
144+
t1 = high_resolution_clock::now();
145+
for (unsigned int i = 0; i < 50'000; i++) {
146+
if (unTestingRVA != cRTTI3.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
147+
printf("Error: Data error!\n");
148+
}
149+
}
150+
t2 = high_resolution_clock::now();
151+
printf("Bench (50 000 calls + MinIterations)............= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
152+
153+
// Stage 4
154+
t1 = high_resolution_clock::now();
155+
for (unsigned char i = 0; i < 100; ++i) {
156+
if (unTestingRVA != cRTTI4.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
157+
printf("Error: Data error!\n");
158+
}
159+
}
160+
t2 = high_resolution_clock::now();
161+
printf("Bench (100 calls + Cache + MinIterations).......= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
162+
163+
t1 = high_resolution_clock::now();
164+
for (unsigned short i = 0; i < 1'000; ++i) {
165+
if (unTestingRVA != cRTTI4.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
166+
printf("Error: Data error!\n");
167+
}
168+
}
169+
t2 = high_resolution_clock::now();
170+
printf("Bench (1 000 calls + Cache + MinIterations).....= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
110171

172+
t1 = high_resolution_clock::now();
173+
for (unsigned int i = 0; i < 10'000; ++i) {
174+
if (unTestingRVA != cRTTI4.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
175+
printf("Error: Data error!\n");
176+
}
177+
}
178+
t2 = high_resolution_clock::now();
179+
printf("Bench (10 000 calls + Cache + MinIterations)....= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
180+
181+
t1 = high_resolution_clock::now();
182+
for (unsigned int i = 0; i < 50'000; i++) {
183+
if (unTestingRVA != cRTTI4.GetVTableOffsetFromModule(hTestDLL, "TestingDLL")) {
184+
printf("Error: Data error!\n");
185+
}
186+
}
187+
t2 = high_resolution_clock::now();
188+
printf("Bench (50 000 calls + Cache + MinIterations)....= %lld ms\n", duration_cast<std::chrono::milliseconds>(t2 - t1).count());
189+
111190
#endif // BENCHMARK_TEST
112191

113192
if (!unTestingRVA) {

0 commit comments

Comments
 (0)