Files
Matthew Fioravante f9c3742986 Refactor Font
GetSize(): Remove u32string overload. Add overloads for
* utf8 std::string
* char32_t

Glyph() and Render():
* Don't create new bitmaps for every character.
* Return rect describing glyph size so we don't have to call GetSize()
later.
2020-02-04 23:05:56 -05:00

57 lines
1.1 KiB
C++

#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();