-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark.cpp
84 lines (63 loc) · 2.12 KB
/
benchmark.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <array>
#include <cmath>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <random>
#include "proj.hpp"
using our_clock = std::chrono::high_resolution_clock;
template <class Func>
std::chrono::milliseconds timethis(Func&& func) {
std::chrono::time_point<our_clock> start{our_clock::now()};
func();
std::chrono::time_point<our_clock> stop{our_clock::now()};
return std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
}
int main() {
std::mt19937_64 gen;
std::uniform_real_distribution<double> dis{-85.0, 85.0};
const int num = 10000000;
std::vector<double> data, r1, r2, r3;
data.resize(num);
r1.resize(num);
r2.resize(num);
r3.resize(num);
for (auto& val : data) {
val = dis(gen);
}
auto d_tan = timethis([&](){
int i = 0;
for (auto& val : data) {
r1[i++] = lat_to_y_with_tan(val);
}
});
std::cout << "tan : " << std::setw(5) << d_tan.count() << "ms 100%\n";
auto d_sin = timethis([&](){
int i = 0;
for (auto& val : data) {
r2[i++] = lat_to_y_with_sin(val);
}
});
std::cout << "sin : " << std::setw(5) << d_sin.count() << "ms " << std::setw(3) << (d_sin * 100 / d_tan) << "%\n";
auto d_poly = timethis([&](){
int i = 0;
for (auto& val : data) {
r3[i++] = lat_to_y_with_poly(val);
}
});
std::cout << "polynom : " << std::setw(5) << d_poly.count() << "ms " << std::setw(3) << (d_poly * 100 / d_tan) << "%\n";
auto d_poly_unrolled = timethis([&](){
int i = 0;
for (auto& val : data) {
r3[i++] = lat_to_y_unrolled(val);
}
});
std::cout << "unrolled : " << std::setw(5) << d_poly_unrolled.count() << "ms " << std::setw(3) << (d_poly_unrolled * 100 / d_tan) << "%\n";
auto d_fixed = timethis([&](){
int i = 0;
for (auto& val : data) {
r3[i++] = lat_to_y_fixed(val);
}
});
std::cout << "fixed : " << std::setw(5) << d_fixed.count() << "ms " << std::setw(3) << (d_fixed * 100 / d_tan) << "%\n";
}