Skip to content

Commit

Permalink
Adding benchmark on pre-decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
aescande committed Feb 5, 2024
1 parent 40e4813 commit 87403d3
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ addBenchmark(BasicEigen)
addBenchmark(Decomposition)
addBenchmark(LinearSystemSolving)

addBenchmark(SolverPreDecomposition problemAdaptors.cpp)
addBenchmark(Solvers problemAdaptors.cpp)
addBenchmark(SolversWarmStart problemAdaptors.cpp)
addBenchmark(BoxAndSingleConstraintSolver)
Expand Down
153 changes: 153 additions & 0 deletions benchmarks/SolverPreDecomposition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* Copyright 2024 CNRS-AIST JRL, Inria */

#include <array>
#include <iostream>

#include <benchmark/benchmark.h>

#include <jrl-qp/GoldfarbIdnaniSolver.h>
#include <jrl-qp/test/randomProblems.h>

using namespace Eigen;
using namespace jrl::qp;
using namespace jrl::qp::test;

template<int N, int EqPercentage>
class ProblemFixture : public ::benchmark::Fixture
{
public:
void SetUp(const ::benchmark::State & st)
{
i = 0;

int n = static_cast<int>(st.range(0));
int neq = nEq(n);

for(int k = 0; k < N; ++k)
{
qpp[k] = QPProblem(randomProblem(ProblemCharacteristics(n, n, neq, 0)));
qpp[k].C.transposeInPlace();
G[k] = qpp[k].G;
}
}

void TearDown(const ::benchmark::State &)
{
}

int idx() const
{
int ret = i % N;
++i;
return ret;
}

static int nEq(int nVar)
{
return static_cast<int>((nVar * EqPercentage) / 100);
}

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

QPProblem<> & getGIPb()
{
int i = idx();
qpp[i].G = G[i];
return qpp[i];
}

private:
mutable int i = 0;
std::array<MatrixXd, N> G;
std::array<QPProblem<>, N> qpp;
};

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);

BENCHMARK_DEFINE_F(test0, 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();
Eigen::internal::llt_inplace<double, Eigen::Lower>::blocked(pb.G);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_INV_0)(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);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_INV_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_INVT_0)(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();
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_INVT_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);

BENCHMARK_DEFINE_F(test0, DECOMP_TINV_0)(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.transpose().solveInPlace(J);
}
}
BENCHMARK_REGISTER_F(test0, DECOMP_TINV_0)->Unit(benchmark::kMicrosecond)->DenseRange(10, 100, 10);


BENCHMARK_MAIN();

0 comments on commit 87403d3

Please sign in to comment.