forked from codex31373/HPC_FMI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_float_double.hpp
executable file
·67 lines (55 loc) · 1.46 KB
/
test_float_double.hpp
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
#pragma once
#include "diffclock.h"
namespace FloatDouble {
size_t constexpr getTestSize() {
return 1_million;
}
NO_INLINE
double testDouble(double f) {
for (int i = 0; i < getTestSize(); ++i) {
auto t = cos(f);
if (pow(t, 3.0) < 0.5) {
t += 5 * t;
t -= 2 * sin(t);
}
f += t;
if (f > 0.1) {
f /= 10.0;
f += randomFloat();
}
f *= 196.0;
}
return f;
}
NO_INLINE
float testFloat(float f) {
for (int i = 0; i < getTestSize(); ++i) {
auto t = cosf(f);
if (powf(t, 3.0f) < 0.5f) {
t += 5 * t;
t -= 2 * sinf(t);
}
f += t;
if (f > 0.1f) {
f /= 10.0f;
f += randomFloat();
}
f *= 196.0f;
}
return f;
}
void test() {
std::cout << "Testing float vs double ..." << std::endl;
auto d = 0.0;
auto test0 = [&] {
d += testDouble(d);
};
auto f = 0.0f;
auto test1 = [&] {
f += testFloat(d);
};
ADD_BENCHMARK("FloatVSDouble \t Double", test0);
ADD_BENCHMARK("FloatVSDouble \t Float", test1);
benchpress::run_benchmarks(benchpress::options());
}
}