Refactoring CMake configs, adding Catch2 benchmark support
This commit is contained in:
@@ -11,5 +11,7 @@ add_executable(tests main.cpp
|
||||
unit_utilities.cpp
|
||||
# integration tests
|
||||
int_basic.cpp
|
||||
# Performance checks
|
||||
perf_dag.cpp
|
||||
)
|
||||
target_link_libraries(tests libdaggy stdc++fs Catch2::Catch2)
|
||||
target_link_libraries(tests libdaggy stdc++fs Catch2::Catch2)
|
||||
|
||||
64
tests/perf_dag.cpp
Normal file
64
tests/perf_dag.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifdef CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "daggy/DAG.hpp"
|
||||
|
||||
inline std::string taskName(size_t i)
|
||||
{
|
||||
return "action_node" + std::to_string(i);
|
||||
}
|
||||
|
||||
daggy::DAG<std::string, size_t> createDAG(size_t N_NODES, size_t MAX_CHILDREN)
|
||||
{
|
||||
daggy::DAG<std::string, size_t> dag;
|
||||
|
||||
for (size_t i = 0; i < N_NODES; ++i) {
|
||||
dag.addVertex(taskName(i), i);
|
||||
}
|
||||
|
||||
static std::random_device dev;
|
||||
static std::mt19937 rng(dev());
|
||||
std::uniform_int_distribution<size_t> nDepDist(1, MAX_CHILDREN);
|
||||
|
||||
for (size_t i = 0; i < N_NODES - 1; ++i) {
|
||||
std::string parent = taskName(i);
|
||||
std::uniform_int_distribution<size_t> depDist(i + 1, N_NODES - 1);
|
||||
size_t nChildren = std::min(nDepDist(rng), N_NODES - i);
|
||||
|
||||
std::unordered_set<size_t> found;
|
||||
size_t tries = 0;
|
||||
while (found.size() < nChildren) {
|
||||
++tries;
|
||||
if (tries > nChildren * 2)
|
||||
break;
|
||||
auto child = depDist(rng);
|
||||
if (found.count(child) > 0)
|
||||
continue;
|
||||
found.insert(child);
|
||||
dag.addEdge(parent, taskName(child));
|
||||
}
|
||||
}
|
||||
|
||||
return dag;
|
||||
}
|
||||
|
||||
const size_t N_NODES = 10'000;
|
||||
const size_t MAX_CHILDREN = 10;
|
||||
|
||||
static auto DAG = createDAG(N_NODES, MAX_CHILDREN);
|
||||
|
||||
TEST_CASE("massive DAGs", "[dag_performance]")
|
||||
{
|
||||
BENCHMARK_ADVANCED("dag.reset")(Catch::Benchmark::Chronometer meter)
|
||||
{
|
||||
meter.measure([&] { return DAG.reset(); });
|
||||
};
|
||||
|
||||
BENCHMARK_ADVANCED("dag.isValid")(Catch::Benchmark::Chronometer meter)
|
||||
{
|
||||
meter.measure([&] { return DAG.isValid(); });
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user