sdl_runtime_compiler git · main
SDL3 game for running and compiling code at runtime
C++ 72.3% C 26.2%git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gzbenchmark/bench_ai.cpp raw
#include <benchmark/benchmark.h>
#include <vector>
#include "systems/word_ai_system.hpp"
#include "systems/carry_system.hpp"
#include "entities/player.hpp"
#include "text/token.hpp"
namespace
Nimbin
{
// What's the per-frame cost of my AI system, and does it scale with the number of words?
static void BM_WordAiUpdate(benchmark::State& state)
{
const size_t N = static_cast<size_t>(state.range(0));
Player player;
player.pos = { 0.0, 0.0, 0.0 };
CarriedLine carried;
DynArray<Text::TokenPtr> words;
words.reserve(N);
for (size_t i = 0; i < N; ++i) {
double angle = (static_cast<double>(i) / N) * 6.28318;
Vec3 pos { 5.0 * SDL_cos(angle), 0.0, 5.0 * SDL_sin(angle) };
words.push_back(Text::make_Token("hover", Text::Token::depth_floor, 0.003f, pos));
}
WordAiSystem ai;
DynArray<Text::TokenPtr> dropped;
constexpr double dt = 1.0 / 60.0;
for (auto _ : state) {
dropped.clear();
ai.update(words, player, carried, dropped, dt);
}
state.SetLabel("N=" + std::to_string(N));
}
BENCHMARK(BM_WordAiUpdate)->Arg(10)->Arg(50)->Arg(100)->Arg(200);
} // namespace Nimbin