Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / benchmark/bench_physics.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_physics.cpp 1.2 KB · 43 lines raw
#include <benchmark/benchmark.h>
#include <vector>

#include "systems/physics_system.hpp"
#include "entities/solid_box.hpp"

// Does my physics update scale linearly or quadratically with object count?

namespace
Nimbin
{

static void BM_PhysicsUpdateObjects(benchmark::State& state)
{
    const size_t N = static_cast<size_t>(state.range(0));

    std::vector<cpputils::unique_ptr<SolidBox>> owners;
    std::vector<GameObject*>                    objects;
    owners.reserve(N);
    objects.reserve(N);

    for (size_t i = 0; i < N; ++i) {
        double x = static_cast<double>(i % 10) * 2.5;
        double z = static_cast<double>(i / 10) * 2.5;
        auto box = cpputils::make_unique<SolidBox>(Vec3{x, 0.0, z}, Vec3{0.5, 0.5, 0.5});
        box->body.mode = PhysicsMode::Dynamic;
        box->body.vel  = { 0.1, 0.0, 0.0 };
        objects.push_back(box.get());
        owners.push_back(std::move(box));
    }

    PhysicsSystem sys;
    constexpr double dt = 1.0 / 60.0;

    for (auto _ : state) {
        sys.update_Objects(objects, dt, 25.0);
    }

    state.SetLabel("N=" + std::to_string(N));
}
BENCHMARK(BM_PhysicsUpdateObjects)->Arg(10)->Arg(50)->Arg(100)->Arg(200);

} // namespace Nimbin