forked from BoostGSoC18/Real
-
Notifications
You must be signed in to change notification settings - Fork 5
/
real_op_evaluation_bench.cpp
116 lines (93 loc) · 4.79 KB
/
real_op_evaluation_bench.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
#include <benchmark/benchmark.h>
#include <benchmark_helpers.hpp>
const int MIN_TREE_NODES = 10;
const int MAX_TREE_NODES = 10000;
const int MULTIPLIER_TE = 10; // for range evaluation of tree evaluation benchmarks
/// benchmarks the evaluation speed of doing a op= b, n times, where n is the set of powers of
/// MULTIPLIER_TE between MIN_TREE_NODES and MAX_TREE_NODES
void BM_RealOperationTreeEvaluation(benchmark::State& state, boost::real::OPERATION op) {
for (auto i : state) {
boost::real::real<> a ("12");
boost::real::real<> b ("34");
state.PauseTiming();
for (int i = 0; i < state.range(0); i++) {
realOperationEq(a,b,op);
}
state.ResumeTiming();
a.get_real_itr().cend(); // force evaluation
state.SetComplexityN(state.range(0));
}
}
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, addition, boost::real::OPERATION(boost::real::OPERATION::ADDITION))
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, subtraction, boost::real::OPERATION(boost::real::OPERATION::SUBTRACTION))
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, multiplication, boost::real::OPERATION(boost::real::OPERATION::MULTIPLICATION))
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, division, boost::real::OPERATION(boost::real::OPERATION::DIVISION))
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond)
->Complexity();
const int MIN_NUM_DIGITS = 1;
const int MAX_NUM_DIGITS = 100 ;
const int MULTIPLIER_OE = 10;
/// benchmarks a op= b, where a, b, have n digits, where n is the set of powers of
/// MULTIPLIER_OE, between MIN_NUM_DIGITS and MAX_NUM_DIGITS
void BM_RealOperationEvaluation(benchmark::State& state, boost::real::OPERATION op) {
for (auto i : state) {
state.PauseTiming(); // construct a, b
std::string tmp;
for (int i = 0; i < state.range(0); i++) {
tmp.push_back('2');
}
boost::real::real<> a(tmp);
tmp.clear();
for (int i = 0; i < state.range(0); i++) {
tmp.push_back('3');
}
boost::real::real<> b(tmp);
realOperationEq(a,b,op);
state.ResumeTiming();
a.get_real_itr().cend(); // force evaluation
state.SetComplexityN(state.range(0));
}
}
// The BM_RealOperationEvaluation operations are much faster, so these use nanoseconds in the result.
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, addition, boost::real::OPERATION(boost::real::OPERATION::ADDITION))
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, subtraction, boost::real::OPERATION(boost::real::OPERATION::SUBTRACTION))
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, multiplication, boost::real::OPERATION(boost::real::OPERATION::MULTIPLICATION))
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)
->Complexity();
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, division, boost::real::OPERATION(boost::real::OPERATION::DIVISION))
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)
->Complexity();
/// benchmarks operator> operator< and operator== for numbers a, b, where a == b, with n digits
void BM_RealComparisonEvaluation(benchmark::State& state, Comparison comp) {
for (auto i : state) {
state.PauseTiming(); // construct a, b
std::string tmp;
for (int i = 0; i < state.range(0); i++) { // we compare 111...1 and 111..1
tmp.push_back('1');
}
boost::real::real<> a(tmp);
boost::real::real<> b(tmp);
state.ResumeTiming();
bool boo = realComp(a,b,comp); // evaluation
state.SetComplexityN(state.range(0));
}
}
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, LESS_THAN, Comparison::LESS_THAN)
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond)
->Complexity();
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, GREATER_THAN, Comparison::GREATER_THAN)
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond)
->Complexity();
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, EQUALS, Comparison::EQUALS)
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond)
->Complexity();