forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.cpp
56 lines (45 loc) · 1.15 KB
/
font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <benchmark/benchmark.h>
#include <font.h>
#include <rect.h>
#include <bitmap.h>
#include <pixel_format.h>
#include <cache.h>
const std::string text = "Alex landed a critical hit on Slime!";
char32_t symbol = '\\';
constexpr int width = 240;
constexpr int height = 80;
static void BM_FontSizeStr(benchmark::State& state) {
auto font = Font::Default();
for (auto _: state) {
auto rect = font->GetSize(text);
(void)rect;
}
}
BENCHMARK(BM_FontSizeStr);
static void BM_FontSizeChar(benchmark::State& state) {
auto font = Font::Default();
for (auto _: state) {
auto rect = font->GetSize(symbol);
(void)rect;
}
}
BENCHMARK(BM_FontSizeChar);
static void BM_Glyph(benchmark::State& state) {
auto font = Font::Default();
for (auto _: state) {
auto bm = font->Glyph(symbol);
(void)bm;
}
}
BENCHMARK(BM_Glyph);
static void BM_Render(benchmark::State& state) {
Bitmap::SetFormat(format_R8G8B8A8_a().format());
auto surface = Bitmap::Create(width, height);
auto system = Cache::SystemOrBlack();
auto font = Font::Default();
for (auto _: state) {
font->Render(*surface, 0, 0, *system, 0, symbol);
}
}
BENCHMARK(BM_Render);
BENCHMARK_MAIN();