Skip to content

Commit

Permalink
Expand benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
aescande committed Feb 8, 2024
1 parent 97db6b4 commit b59d348
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 57 deletions.
1 change: 0 additions & 1 deletion benchmarks/LinearSystemSolving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ BENCHMARK(BM_TriangularInverse_Transpose)->Apply(testSizes)->Unit(benchmark::kMi
invA.col(i1).head(i1 - 1) = -invA(i1, i1) * A.row(i1).head(i1 - 1).transpose();
invA.col(i + 1).head(i) = invA.topLeftCorner(i, i) * invA.col(i + 1).head(i);
}
A.template triangularView<Eigen::Lower>().transpose().solveInPlace(invA);
}
}
BENCHMARK(BM_TriangularInverse_Transpose_ByHand)->Apply(testSizes)->Unit(benchmark::kMicrosecond);
Expand Down
142 changes: 86 additions & 56 deletions benchmarks/SolverPreDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class ProblemFixture : public ::benchmark::Fixture
return static_cast<int>((nVar * EqPercentage) / 100);
}

const LeastSquareProblem<> & getBSCPb() const
{
return pb[idx()];
}

QPProblem<> & getGIPb()
{
int i = idx();
Expand All @@ -64,87 +59,122 @@ class ProblemFixture : public ::benchmark::Fixture
};

using test0 = ProblemFixture<1000, 0>;
BENCHMARK_DEFINE_F(test0, NO_PRE_DECOMP_0)(benchmark::State & st)
{
int n = static_cast<int>(st.range(0));
int neq = test0::nEq(n);
GoldfarbIdnaniSolver solver(n, neq, false);

for(auto _ : st)
{
auto & pb = getGIPb();
solver.solve(pb.G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu);
}
}
BENCHMARK_REGISTER_F(test0, NO_PRE_DECOMP_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);
using test50 = ProblemFixture<1000, 50>;

BENCHMARK_DEFINE_F(test0, DECOMP_0)(benchmark::State & st)
BENCHMARK_DEFINE_F(test0, LLT_INTERNAL)(benchmark::State & st)
{
int n = static_cast<int>(st.range(0));
int neq = test0::nEq(n);
GoldfarbIdnaniSolver solver(n, neq, false);

for(auto _ : st)
{
auto & pb = getGIPb();
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);
BENCHMARK_REGISTER_F(test0, LLT_INTERNAL)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_INV_0)(benchmark::State & st)
BENCHMARK_DEFINE_F(test0, LLT_FUNCTION)(benchmark::State & st)
{
int n = static_cast<int>(st.range(0));
int neq = test0::nEq(n);
GoldfarbIdnaniSolver solver(n, neq, false);
MatrixXd J(n, n);

for(auto _ : st)
{
auto & pb = getGIPb();
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G);
auto L = pb.G.template triangularView<Eigen::Lower>();
J.setIdentity();
L.solveInPlace(J);
auto llt = pb.G.llt();
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_INV_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);
BENCHMARK_REGISTER_F(test0, LLT_FUNCTION)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_INVT_0)(benchmark::State & st)
BENCHMARK_DEFINE_F(test0, LLT_OBJECT)(benchmark::State & st)
{
int n = static_cast<int>(st.range(0));
int neq = test0::nEq(n);
GoldfarbIdnaniSolver solver(n, neq, false);
MatrixXd J(n, n);

for(auto _ : st)
{
auto & pb = getGIPb();
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G);
auto L = pb.G.template triangularView<Eigen::Lower>();
J.setIdentity();
L.solveInPlace(J);
J.transposeInPlace();
LLT<MatrixXd> llt(pb.G);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_INVT_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);
BENCHMARK_REGISTER_F(test0, LLT_OBJECT)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_TINV_0)(benchmark::State & st)
BENCHMARK_DEFINE_F(test0, LLT_PREALLOC)(benchmark::State & st)
{
int n = static_cast<int>(st.range(0));
int neq = test0::nEq(n);
GoldfarbIdnaniSolver solver(n, neq, false);
MatrixXd J(n, n);
LLT<MatrixXd> llt(n);

for(auto _ : st)
{
auto & pb = getGIPb();
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G);
auto L = pb.G.template triangularView<Eigen::Lower>();
J.setIdentity();
L.transpose().solveInPlace(J);
llt.compute(pb.G);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_TINV_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);
BENCHMARK_REGISTER_F(test0, LLT_PREALLOC)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

#define BENCH_DECOMP(fixture) \
BENCHMARK_DEFINE_F(fixture, NO_PRE_DECOMP)(benchmark::State & st) \
{ \
int n = static_cast<int>(st.range(0)); \
int neq = fixture::nEq(n); \
GoldfarbIdnaniSolver solver(n, neq, false); \
\
for(auto _ : st) \
{ \
auto & pb = getGIPb(); \
solver.solve(pb.G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu); \
} \
} \
BENCHMARK_REGISTER_F(fixture, NO_PRE_DECOMP)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10); \
\
BENCHMARK_DEFINE_F(fixture, DECOMP_INV)(benchmark::State & st) \
{ \
int n = static_cast<int>(st.range(0)); \
int neq = fixture::nEq(n); \
GoldfarbIdnaniSolver solver(n, neq, false); \
MatrixXd J(n, n); \
\
for(auto _ : st) \
{ \
auto & pb = getGIPb(); \
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G); \
auto L = pb.G.template triangularView<Eigen::Lower>(); \
J.setIdentity(); \
L.solveInPlace(J); \
} \
} \
BENCHMARK_REGISTER_F(fixture, DECOMP_INV)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10); \
\
BENCHMARK_DEFINE_F(fixture, DECOMP_INVT)(benchmark::State & st) \
{ \
int n = static_cast<int>(st.range(0)); \
int neq = fixture::nEq(n); \
GoldfarbIdnaniSolver solver(n, neq, false); \
MatrixXd J(n, n); \
\
for(auto _ : st) \
{ \
auto & pb = getGIPb(); \
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G); \
auto L = pb.G.template triangularView<Eigen::Lower>(); \
J.setIdentity(); \
L.solveInPlace(J); \
J.transposeInPlace(); \
} \
} \
BENCHMARK_REGISTER_F(fixture, DECOMP_INVT)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10); \
\
BENCHMARK_DEFINE_F(fixture, DECOMP_TINV)(benchmark::State & st) \
{ \
int n = static_cast<int>(st.range(0)); \
int neq = fixture::nEq(n); \
GoldfarbIdnaniSolver solver(n, neq, false); \
MatrixXd J(n, n); \
\
for(auto _ : st) \
{ \
auto & pb = getGIPb(); \
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G); \
auto L = pb.G.template triangularView<Eigen::Lower>(); \
J.setIdentity(); \
L.transpose().solveInPlace(J); \
} \
} \
BENCHMARK_REGISTER_F(fixture, DECOMP_TINV)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCH_DECOMP(test0)
BENCH_DECOMP(test50)

BENCHMARK_MAIN();

0 comments on commit b59d348

Please sign in to comment.