Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / benchmark/bench_ai.cpp

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

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.gz
benchmark/bench_ai.cpp 1.1 KB · 46 lines 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