forked from stan-dev/perf-math
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheigen_return.cpp
More file actions
39 lines (31 loc) · 824 Bytes
/
eigen_return.cpp
File metadata and controls
39 lines (31 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <benchmark/benchmark.h>
#include <Eigen/Dense>
#include <stan/math/rev/core.hpp>
using Eigen::MatrixXd;
using namespace stan::math;
MatrixXd inplace(MatrixXd& L_A) {
Eigen::LLT<Eigen::Ref<Eigen::MatrixXd>, Eigen::Lower> L_factor(L_A);
return L_A;
}
MatrixXd returncopy(const MatrixXd& m) {
Eigen::LLT<MatrixXd> llt(m.rows());
llt.compute(m);
return llt.matrixL();
}
static void ReturnCopy(benchmark::State& state) {
auto m_d = MatrixXd::Random(500, 500).eval();
MatrixXd result(500, 500);
for (auto _ : state) {
result = returncopy(m_d);
}
}
BENCHMARK(ReturnCopy);
static void Inplace(benchmark::State& state) {
auto m_d = MatrixXd::Random(500, 500).eval();
MatrixXd result(500, 500);
for (auto _ : state) {
result = inplace(m_d);
}
}
BENCHMARK(Inplace);
BENCHMARK_MAIN();