-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbench_Cl.cpp
122 lines (90 loc) · 3.37 KB
/
bench_Cl.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "alt.h"
#include "bench.hpp"
#include "Cl2.hpp"
#include "Cl3.hpp"
#include "Cl4.hpp"
#include "Cl5.hpp"
#include "Cl6.hpp"
#include "Li2.hpp"
#include <iostream>
#include <iomanip>
#ifdef ENABLE_GSL
#include <gsl/gsl_sf_clausen.h>
#endif
namespace {
double Cl2_via_Li2(double x) noexcept
{
return std::imag(polylogarithm::Li2(std::exp(std::complex<double>(0.0, x))));
}
long double Cl2_via_Li2(long double x) noexcept
{
return std::imag(polylogarithm::Li2(std::exp(std::complex<long double>(0.0L, x))));
}
} // anonymous namespace
template <typename T, typename Fn>
void bench_fn(Fn f, const std::vector<T>& values, const std::string& name,
const std::string& type)
{
const auto total_time = polylogarithm::bench::time_in_seconds([&] {
for (const auto& v: values) {
polylogarithm::bench::do_not_optimize(f(v));
}
});
std::cout << std::setw(24) << std::left << name << "type: " << std::setw(16)
<< std::left << type << "time: " << total_time << "s\n";
}
void print_line()
{
std::cout << "----------------------------------------------------------------\n";
}
void print_headline(const std::string& text)
{
print_line();
std::cout << text << '\n';
print_line();
}
int main() {
using polylogarithm::bench::generate_random_scalars;
using polylogarithm::bench::generate_random_complexes;
const std::size_t N = 1000000;
const auto min = 0.0;
const auto max = 3.1415926535897932;
const auto values_d = generate_random_scalars<double>(N, min, max);
const auto values_l = generate_random_scalars<long double>(N, min, max);
print_headline("Cl2");
bench_fn([&](double x) { return polylogarithm::Cl2(x); }, values_d,
"polylogarithm C++", "double");
bench_fn([&](double x) { return Cl2_via_Li2(x); }, values_d,
"via Li2 C++", "double");
bench_fn([&](double x) { return koelbig_cl2(x); }, values_d,
"Koelbig C", "double");
#ifdef ENABLE_GSL
bench_fn([&](double x) { return gsl_sf_clausen(x); }, values_d,
"GSL", "double");
#endif
bench_fn([&](long double x) { return polylogarithm::Cl2(x); }, values_l,
"polylogarithm C++", "long double");
bench_fn([&](long double x) { return Cl2_via_Li2(x); }, values_l,
"via Li2 C++", "long double");
print_headline("Cl3");
bench_fn([&](double x) { return polylogarithm::Cl3(x); }, values_d,
"polylogarithm C++", "double");
bench_fn([&](long double x) { return polylogarithm::Cl3(x); }, values_l,
"polylogarithm C++", "long double");
print_headline("Cl4");
bench_fn([&](double x) { return polylogarithm::Cl4(x); }, values_d,
"polylogarithm C++", "double");
bench_fn([&](long double x) { return polylogarithm::Cl4(x); }, values_l,
"polylogarithm C++", "long double");
print_headline("Cl5");
bench_fn([&](double x) { return polylogarithm::Cl5(x); }, values_d,
"polylogarithm C++", "double");
bench_fn([&](long double x) { return polylogarithm::Cl5(x); }, values_l,
"polylogarithm C++", "long double");
print_headline("Cl6");
bench_fn([&](double x) { return polylogarithm::Cl6(x); }, values_d,
"polylogarithm C++", "double");
bench_fn([&](long double x) { return polylogarithm::Cl6(x); }, values_l,
"polylogarithm C++", "long double");
return 0;
}