Skip to content

Commit 0e27555

Browse files
committed
Fix broad phase benchmark
1 parent b9a841f commit 0e27555

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

tests/src/tests/broad_phase/benchmark_broad_phase.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ TEST_CASE("Benchmark broad phase", "[!benchmark][broad_phase]")
6565
F_stack.bottomRows(F.rows()) = F.array() + n;
6666
F = F_stack;
6767

68+
Eigen::MatrixXi E_stack(2 * E.rows(), E.cols());
69+
E_stack.topRows(E.rows()) = E;
70+
E_stack.bottomRows(E.rows()) = E.array() + n;
71+
E = E_stack;
72+
6873
testcase_name = fmt::format("Interobject dx={}", dx);
6974
}
7075

@@ -75,13 +80,15 @@ TEST_CASE("Benchmark broad phase", "[!benchmark][broad_phase]")
7580
V0 = mesh.vertices(V0);
7681
V1 = mesh.vertices(V1);
7782

78-
const auto broad_phase = GENERATE(tests::BroadPhaseGenerator::create());
83+
const auto broad_phases = tests::broad_phases();
7984

80-
BENCHMARK(fmt::format("BP {} ({})", testcase_name, broad_phase->name()))
81-
{
82-
Candidates candidates;
83-
candidates.build(mesh, V0, V1, inflation_radius, broad_phase);
84-
};
85+
for (const auto& broad_phase : broad_phases) {
86+
BENCHMARK(fmt::format("BP {} ({})", testcase_name, broad_phase->name()))
87+
{
88+
Candidates candidates;
89+
candidates.build(mesh, V0, V1, inflation_radius, broad_phase);
90+
};
91+
}
8592
}
8693

8794
TEST_CASE(
@@ -125,14 +132,17 @@ TEST_CASE(
125132
V0 = mesh.vertices(V0);
126133
V1 = mesh.vertices(V1);
127134

128-
const auto broad_phase = GENERATE(tests::BroadPhaseGenerator::create());
129-
if (broad_phase->name() == "BruteForce") {
130-
SKIP("Not benchmarking brute force");
131-
}
135+
const auto broad_phases = tests::broad_phases();
132136

133-
BENCHMARK(fmt::format("BP Real Data ({})", broad_phase->name()))
134-
{
135-
Candidates candidates;
136-
candidates.build(mesh, V0, V1, inflation_radius, broad_phase);
137-
};
137+
for (const auto& broad_phase : broad_phases) {
138+
if (broad_phase->name() == "BruteForce") {
139+
continue;
140+
}
141+
142+
BENCHMARK(fmt::format("BP Real Data ({})", broad_phase->name()))
143+
{
144+
Candidates candidates;
145+
candidates.build(mesh, V0, V1, inflation_radius, broad_phase);
146+
};
147+
}
138148
}

tests/src/tests/utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
namespace ipc::tests {
2222

23-
BroadPhaseGenerator::BroadPhaseGenerator()
23+
std::vector<std::shared_ptr<BroadPhase>> broad_phases()
2424
{
25-
m_broad_phases = { {
25+
return { {
2626
std::make_shared<BruteForce>(),
2727
std::make_shared<HashGrid>(),
2828
std::make_shared<SpatialHash>(),
@@ -34,6 +34,8 @@ BroadPhaseGenerator::BroadPhaseGenerator()
3434
} };
3535
}
3636

37+
BroadPhaseGenerator::BroadPhaseGenerator() { m_broad_phases = broad_phases(); }
38+
3739
// Attempts to move the generator to the next element.
3840
// Returns true if successful (and thus has another element that can be
3941
// read)

tests/src/tests/utils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class BroadPhaseGenerator
3535
int m_current = 0;
3636
};
3737

38+
std::vector<std::shared_ptr<BroadPhase>> broad_phases();
39+
3840
// ============================================================================
3941

4042
bool load_mesh(

0 commit comments

Comments
 (0)