Skip to content

Commit 205fb4e

Browse files
committed
v9.9
1 parent 3b3326d commit 205fb4e

File tree

6 files changed

+100
-245
lines changed

6 files changed

+100
-245
lines changed

bench/bench.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "pal/pal_core.h"
66

7+
#define MAX_ITERATIONS 1000
8+
79
typedef void (*BenchFn)();
810

911
void runBench(
@@ -12,6 +14,6 @@ void runBench(
1214
Int32 iterations);
1315

1416
void windowBench();
15-
void windowUpdateBench();
17+
void windowBenchPlatform();
1618

1719
#endif // _BENCH_H

bench/bench.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ project "bench"
1414
if (PAL_BUILD_VIDEO) then
1515
files {
1616
"window_bench.c",
17-
"window_update_bench.c"
17+
"window_bench_platform.c"
1818
}
1919
end
2020

bench/bench_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main(int argc, char** argv)
1010

1111
#if PAL_HAS_VIDEO
1212
windowBench();
13-
windowUpdateBench();
13+
windowBenchPlatform();
1414
#endif // PAL_HAS_VIDEO
1515

1616
return 0;

bench/window_bench.c

Lines changed: 4 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,6 @@
22
#include "bench.h"
33
#include "pal/pal_video.h"
44

5-
#ifdef _WIN32
6-
#ifndef WIN32_LEAN_AND_MEAN
7-
#define WIN32_LEAN_AND_MEAN
8-
#endif // WIN32_LEAN_AND_MEAN
9-
10-
#ifndef NOMINMAX
11-
#define NOMINMAX
12-
#endif // NOMINMAX
13-
14-
// set unicode
15-
#ifndef UNICODE
16-
#define UNICODE
17-
#endif // UNICODE
18-
19-
#include <windows.h>
20-
21-
#define PLATFORM_CLASS L"Platform"
22-
static HINSTANCE g_Instance;
23-
24-
#endif // _WIN32
25-
26-
#define MAX_ITERATIONS 1000
27-
285
static inline void createDestroy()
296
{
307
PalResult result;
@@ -39,93 +16,26 @@ static inline void createDestroy()
3916

4017
result = palCreateWindow(&createInfo, &window);
4118
if (result != PAL_RESULT_SUCCESS) {
42-
palLog(nullptr, "Failed to create window %s", palFormatResult(result));
19+
const char* error = palFormatResult(result);
20+
palLog(nullptr, "Failed to create window %s", error);
4321
return;
4422
}
4523

4624
palDestroyWindow(window);
4725
}
4826

49-
static inline void createDestroyPlatform()
50-
{
51-
HWND window = nullptr;
52-
Uint32 style = WS_OVERLAPPEDWINDOW;
53-
Uint32 exStyle = WS_EX_APPWINDOW;
54-
55-
window = CreateWindowExW(
56-
exStyle,
57-
PLATFORM_CLASS,
58-
L"Platform Window",
59-
style,
60-
100,
61-
100,
62-
640,
63-
480,
64-
nullptr,
65-
nullptr,
66-
g_Instance,
67-
nullptr);
68-
69-
if (!window) {
70-
palLog(nullptr, "Platform Error");
71-
return;
72-
}
73-
74-
ShowWindow(window, SW_SHOW);
75-
UpdateWindow(window);
76-
SetWindowLongPtrW(window, GWLP_USERDATA, (LONG_PTR)nullptr);
77-
78-
DestroyWindow(window);
79-
}
80-
8127
void windowBench()
8228
{
8329
// initialize PAL video
8430
PalResult result = palInitVideo(nullptr, nullptr);
8531
if (result != PAL_RESULT_SUCCESS) {
86-
palLog(
87-
nullptr,
88-
"Failed to initialize video %s",
89-
palFormatResult(result));
32+
const char* error = palFormatResult(result);
33+
palLog(nullptr, "Failed to initialize video %s", error);
9034
return;
9135
}
9236

93-
// initialize platform video
94-
#ifdef _WIN32
95-
HINSTANCE g_Instance = GetModuleHandleW(nullptr);
96-
97-
// register class
98-
WNDCLASSEXW wc = {0};
99-
wc.cbSize = sizeof(WNDCLASSEXW);
100-
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
101-
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
102-
wc.hIconSm = LoadIconW(NULL, IDI_APPLICATION);
103-
wc.hInstance = g_Instance;
104-
wc.lpfnWndProc = DefWindowProcW;
105-
wc.lpszClassName = PLATFORM_CLASS;
106-
wc.style = CS_OWNDC;
107-
108-
if (!RegisterClassExW(&wc)) {
109-
palLog(nullptr, "Platform Error");
110-
return;
111-
}
112-
#endif // _WIN32
113-
114-
// run benchmarks
115-
// platform
116-
runBench(
117-
createDestroyPlatform,
118-
"Platform Window Benchmark",
119-
MAX_ITERATIONS);
120-
121-
// PAL
12237
runBench(createDestroy, "PAL Window Benchmark", MAX_ITERATIONS);
12338

124-
// shutdown platform video
125-
#ifdef _WIN32
126-
UnregisterClassW(PLATFORM_CLASS, g_Instance);
127-
#endif // _WIN32
128-
12939
// shutdown PAL video
13040
palShutdownVideo();
13141
}

bench/window_bench_platform.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
#include "bench.h"
3+
4+
#ifdef _WIN32
5+
#ifndef WIN32_LEAN_AND_MEAN
6+
#define WIN32_LEAN_AND_MEAN
7+
#endif // WIN32_LEAN_AND_MEAN
8+
9+
#ifndef NOMINMAX
10+
#define NOMINMAX
11+
#endif // NOMINMAX
12+
13+
// set unicode
14+
#ifndef UNICODE
15+
#define UNICODE
16+
#endif // UNICODE
17+
18+
#include <windows.h>
19+
20+
#define PLATFORM_CLASS L"Platform"
21+
static HINSTANCE g_Instance;
22+
23+
#endif // _WIN32
24+
25+
static inline void createDestroy()
26+
{
27+
#ifdef _WIN32
28+
HWND window = nullptr;
29+
Uint32 style = WS_CAPTION | WS_SYSMENU | WS_OVERLAPPED;
30+
style |= WS_MINIMIZEBOX;
31+
style |= WS_MAXIMIZEBOX;
32+
style |= WS_THICKFRAME;
33+
Uint32 exStyle = 0; // just like PAL benchmark
34+
35+
window = CreateWindowExW(
36+
exStyle,
37+
PLATFORM_CLASS,
38+
L"Platform Window",
39+
style,
40+
100,
41+
100,
42+
640,
43+
480,
44+
nullptr,
45+
nullptr,
46+
g_Instance,
47+
nullptr);
48+
49+
if (!window) {
50+
palLog(nullptr, "Platform Error");
51+
return;
52+
}
53+
54+
SetWindowLongPtrW(window, GWLP_USERDATA, (LONG_PTR)nullptr);
55+
ShowWindow(window, SW_SHOW);
56+
UpdateWindow(window);
57+
DestroyWindow(window);
58+
59+
#endif // _WIN32
60+
}
61+
62+
void windowBenchPlatform()
63+
{
64+
// initialize platform video
65+
#ifdef _WIN32
66+
HINSTANCE g_Instance = GetModuleHandleW(nullptr);
67+
68+
// register class
69+
WNDCLASSEXW wc = {0};
70+
wc.cbSize = sizeof(WNDCLASSEXW);
71+
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
72+
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
73+
wc.hIconSm = LoadIconW(NULL, IDI_APPLICATION);
74+
wc.hInstance = g_Instance;
75+
wc.lpfnWndProc = DefWindowProcW;
76+
wc.lpszClassName = PLATFORM_CLASS;
77+
wc.style = CS_OWNDC;
78+
79+
if (!RegisterClassExW(&wc)) {
80+
palLog(nullptr, "Platform Error");
81+
return;
82+
}
83+
#endif // _WIN32
84+
85+
runBench(createDestroy, "Platform Window Benchmark", MAX_ITERATIONS);
86+
87+
// shutdown platform video
88+
#ifdef _WIN32
89+
UnregisterClassW(PLATFORM_CLASS, g_Instance);
90+
#endif // _WIN32
91+
}

0 commit comments

Comments
 (0)