diff --git a/benchmarks/LinearSystemSolving.cpp b/benchmarks/LinearSystemSolving.cpp index 9626e00..8776074 100644 --- a/benchmarks/LinearSystemSolving.cpp +++ b/benchmarks/LinearSystemSolving.cpp @@ -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().transpose().solveInPlace(invA); } } BENCHMARK(BM_TriangularInverse_Transpose_ByHand)->Apply(testSizes)->Unit(benchmark::kMicrosecond); diff --git a/benchmarks/SolverPreDecomposition.cpp b/benchmarks/SolverPreDecomposition.cpp index b21f966..444370f 100644 --- a/benchmarks/SolverPreDecomposition.cpp +++ b/benchmarks/SolverPreDecomposition.cpp @@ -45,11 +45,6 @@ class ProblemFixture : public ::benchmark::Fixture return static_cast((nVar * EqPercentage) / 100); } - const LeastSquareProblem<> & getBSCPb() const - { - return pb[idx()]; - } - QPProblem<> & getGIPb() { int i = idx(); @@ -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(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(st.range(0)); - int neq = test0::nEq(n); - GoldfarbIdnaniSolver solver(n, neq, false); - for(auto _ : st) { auto & pb = getGIPb(); Eigen::internal::llt_inplace::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(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::blocked(pb.G); - auto L = pb.G.template triangularView(); - 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(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::blocked(pb.G); - auto L = pb.G.template triangularView(); - J.setIdentity(); - L.solveInPlace(J); - J.transposeInPlace(); + LLT 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(st.range(0)); - int neq = test0::nEq(n); - GoldfarbIdnaniSolver solver(n, neq, false); - MatrixXd J(n, n); + LLT llt(n); for(auto _ : st) { auto & pb = getGIPb(); - Eigen::internal::llt_inplace::blocked(pb.G); - auto L = pb.G.template triangularView(); - 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(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(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::blocked(pb.G); \ + auto L = pb.G.template triangularView(); \ + 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(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::blocked(pb.G); \ + auto L = pb.G.template triangularView(); \ + 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(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::blocked(pb.G); \ + auto L = pb.G.template triangularView(); \ + 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(); \ No newline at end of file