forked from st-tech/ppf-contact-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench3.cpp
More file actions
49 lines (43 loc) · 1.4 KB
/
bench3.cpp
File metadata and controls
49 lines (43 loc) · 1.4 KB
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
40
41
42
43
44
45
46
47
48
49
// File: bench3.cpp
// Author: Ryoichi Ando (ryoichi.ando@zozo.com)
// License: Apache v2.0
#include "eig-hpp/eigsolve3x3.hpp"
#include <Eigen/Dense>
#include <chrono>
#include <functional>
#include <iostream>
#include <vector>
using namespace Eigen;
void eigen_decompose(const std::vector<Matrix3d> &F) {
for (auto &f : F) {
SelfAdjointEigenSolver<Matrix3d> eigensolver;
eigensolver.computeDirect(f);
}
}
void our_compute(const std::vector<Matrix3d> &F) {
for (auto &f : F) {
auto [_U, lambda, _Vt] = run_svd_3x3(f);
}
}
template <typename Func>
double measure_execution_time(Func func, const std::vector<Matrix3d> &F) {
auto start = std::chrono::high_resolution_clock::now();
func(F);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> duration = end - start;
return duration.count();
}
int main() {
unsigned mat_count = 10000000;
std::vector<Matrix3d> F(mat_count);
for (unsigned i = 0; i < mat_count; ++i) {
Matrix3d a = Matrix3d::Random();
F[i] = a + a.transpose();
}
double time1 = measure_execution_time(eigen_decompose, F);
std::cout << "Eigen: " << time1 << " seconds." << std::endl;
double time2 = measure_execution_time(our_compute, F);
std::cout << "Ours: " << time2 << " seconds." << std::endl;
std::cout << "Speedup factor: " << time1 / time2 << std::endl;
return 0;
}