#include #include #include "text/mesh.hpp" namespace Nimbin { static const std::string FONT = "/usr/share/fonts/dejavu/DejaVuSansMono.ttf"; // Single short word — fastest case static void BM_BuildTextMesh_Short(benchmark::State& state) { TextMesh out; for (auto _ : state) { out.verts.clear(); out.tris.clear(); out.vertex_normals.clear(); benchmark::DoNotOptimize( out.build(FONT, "if", 64, 0.14f, 0.003f) ); } } BENCHMARK(BM_BuildTextMesh_Short); // Medium word static void BM_BuildTextMesh_Medium(benchmark::State& state) { TextMesh out; for (auto _ : state) { out.verts.clear(); out.tris.clear(); out.vertex_normals.clear(); benchmark::DoNotOptimize( out.build(FONT, "function", 64, 0.14f, 0.003f) ); } } BENCHMARK(BM_BuildTextMesh_Medium); // Parameterized over word length static void BM_BuildTextMesh_Length(benchmark::State& state) { std::string text(static_cast(state.range(0)), 'a'); TextMesh out; for (auto _ : state) { out.verts.clear(); out.tris.clear(); out.vertex_normals.clear(); benchmark::DoNotOptimize( out.build(FONT, text, 64, 0.14f, 0.003f) ); } state.SetLabel("len=" + std::to_string(state.range(0))); } BENCHMARK(BM_BuildTextMesh_Length)->Arg(1)->Arg(4)->Arg(8)->Arg(16)->Arg(32); // Different depths shouldn't change cost much (same earcut work, // just different extrusion). Verify. static void BM_BuildTextMesh_Depth(benchmark::State& state) { float depth = static_cast(state.range(0)) / 1000.0f; TextMesh out; for (auto _ : state) { out.verts.clear(); out.tris.clear(); out.vertex_normals.clear(); benchmark::DoNotOptimize( out.build(FONT, "hello", 64, depth, 0.003f) ); } state.SetLabel("depth=" + std::to_string(depth)); } BENCHMARK(BM_BuildTextMesh_Depth)->Arg(20)->Arg(60)->Arg(140); } // namespace Nimbin