diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-06-30 19:05:02 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-06-30 19:05:05 +0100 |
commit | f83d7cc0e2f0f6558783a5f3f146c10417e9225a (patch) | |
tree | c25d723d8e9a3954b41f48c0e7e64d7a6ed8e1cd | |
parent | Fix run rules for perfs (diff) | |
download | ilt-f83d7cc0e2f0f6558783a5f3f146c10417e9225a.tar.bz2 ilt-f83d7cc0e2f0f6558783a5f3f146c10417e9225a.tar.xz ilt-f83d7cc0e2f0f6558783a5f3f146c10417e9225a.zip |
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.
-rw-r--r-- | test/Jamfile.jam | 2 | ||||
-rw-r--r-- | test/perf-instancing.cpp | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 2048adc..1266854 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -60,6 +60,7 @@ run perf-geoData.cpp : : : <library>test <library>benchmark ; run perf-persistence.cpp : \< : test-persistence : <library>benchmark <library>test ; run test-worker.cpp ; run test-instancing.cpp : -- : test-glContainer : <library>test ; +run perf-instancing.cpp : \< : test-instancing : <library>benchmark <library>test ; run test-glContainer.cpp : : : <library>test ; run test-pack.cpp : : : <library>test ; compile test-static-enumDetails.cpp ; @@ -67,5 +68,6 @@ compile test-static-stream_support.cpp ; explicit perf-assetFactory ; explicit perf-persistence ; explicit perf-terrain ; +explicit perf-instancing ; alias perf : perf-assetFactory perf-persistence perf-terrain ; explicit perf ; 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 <benchmark/benchmark.h> +#include <random> + +struct Instance { + GlobalPosition3D pos; + glm::mat3 rot; +}; + +struct data { + explicit data(size_t n) + { + std::mt19937 gen(std::random_device {}()); + std::uniform_int_distribution<GlobalDistance> xy(0, 1000000); + std::uniform_int_distribution<GlobalDistance> z(0, 10000); + while (n--) { + proxies.emplace_back(instances.acquire(GlobalPosition3D {xy(gen), xy(gen), z(gen)}, glm::mat3 {})); + } + } + + InstanceVertices<Instance> instances; + std::vector<InstanceVertices<Instance>::InstanceProxy> proxies; +}; + +static void +partition(benchmark::State & state) +{ + TestMainWindow window; + data d(static_cast<size_t>(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(); |