forked from BoostGSoC19/Real
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation_tree_bench.cpp
52 lines (43 loc) · 1.51 KB
/
operation_tree_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
#include <benchmark/benchmark.h>
#include <real/real.hpp>
#include <benchmark_helpers.hpp>
/** @file benchmark the operation trees,
* with different kinds of leaves, and/or a large number of nodes.
*/
// constants used in the benchmarks
const int MIN_TREE_SIZE = 8;
const int MAX_TREE_SIZE = 16;
// used to force evaluation, without console output
NullStream null_stream;
// trees between MIN_TREE_SIZE and MAX_TREE_SIZE of single operations
static void BM_RealAdditionTree(benchmark::State& state) {
boost::real::real a ("1.2");
boost::real::real c ("0");
for (auto i : state)
for (int i = 0; i < state.range(0); i++)
c += a;
null_stream << c << '\n';
}
BENCHMARK(BM_RealAdditionTree)->Range(MIN_TREE_SIZE,MAX_TREE_SIZE)->Unit(benchmark::kMillisecond);
static void BM_RealSubtractionTree(benchmark::State& state) {
boost::real::real a ("1");
boost::real::real c ("9999");
for (auto i : state)
{
for (int i = 0; i < state.range(0); i++)
c -= a;
null_stream << c << '\n';
}
}
BENCHMARK(BM_RealSubtractionTree)->Range(MIN_TREE_SIZE,MAX_TREE_SIZE)->Unit(benchmark::kMillisecond);
static void BM_RealMultiplicationTree(benchmark::State& state) {
boost::real::real a ("1");
boost::real::real c ("9");
for (auto i : state)
{
for (int i = 0; i < state.range(0); i++)
c *= a;
null_stream << c << '\n';
}
}
BENCHMARK(BM_RealMultiplicationTree)->Range(MIN_TREE_SIZE,MAX_TREE_SIZE)->Unit(benchmark::kMillisecond);