From f83d7cc0e2f0f6558783a5f3f146c10417e9225a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 30 Jun 2024 19:05:02 +0100 Subject: Add an InstanceVertices partition perf test Summary: * Given a trivially simple condition, like a bounding box, over 1 million items can be partitioned in under 3ms. * Parallel algorithms reduce that a little but are only effective with volumes in excess ~200k, this might be better with a more complex condition/predicate. --- test/perf-instancing.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/perf-instancing.cpp (limited to 'test/perf-instancing.cpp') diff --git a/test/perf-instancing.cpp b/test/perf-instancing.cpp new file mode 100644 index 0000000..829ea50 --- /dev/null +++ b/test/perf-instancing.cpp @@ -0,0 +1,43 @@ +#include "gfx/gl/instanceVertices.h" +#include "testMainWindow.h" +#include +#include + +struct Instance { + GlobalPosition3D pos; + glm::mat3 rot; +}; + +struct data { + explicit data(size_t n) + { + std::mt19937 gen(std::random_device {}()); + std::uniform_int_distribution xy(0, 1000000); + std::uniform_int_distribution z(0, 10000); + while (n--) { + proxies.emplace_back(instances.acquire(GlobalPosition3D {xy(gen), xy(gen), z(gen)}, glm::mat3 {})); + } + } + + InstanceVertices instances; + std::vector::InstanceProxy> proxies; +}; + +static void +partition(benchmark::State & state) +{ + TestMainWindow window; + data d(static_cast(state.range())); + GlobalPosition2D pos {}; + for (auto _ : state) { + d.instances.partition([&pos](const auto & i) { + return std::abs(i.pos.x - pos.x) < 5 && std::abs(i.pos.y - pos.y) < 5; + }); + pos += GlobalPosition2D {33, 17}; + pos %= 1000000; + } +} + +BENCHMARK(partition)->Range(0, 1 << 20); + +BENCHMARK_MAIN(); -- cgit v1.2.3