-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
71 lines (55 loc) · 1.74 KB
/
main.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
#include <benchmark/benchmark.h>
#include <boost/multiprecision/cpp_int.hpp>
#include "abseil-cpp/absl/numeric/int128.h"
#include "intx/intx.hpp"
#include <iostream>
template<typename TYPE>
static void create_type(benchmark::State& state) {
for (auto _ : state)
TYPE v = 1;
}
template<typename TYPE>
static void add_type(benchmark::State& state) {
TYPE v = 1;
uint64_t a = 999999;
for (auto _ : state)
v += a;
}
template<typename TYPE>
static void multiply_type(benchmark::State& state) {
TYPE v = 10;
uint64_t a = 2'400;
for (auto _ : state)
v *= a;
}
template<typename TYPE>
static void add_multiply_type(benchmark::State& state) {
TYPE v = 10;
TYPE x = 10;
uint64_t a = 2'400;
for (auto _ : state)
x += v * a;
}
#define BENCHMARK_TYPE(TYPE) \
BENCHMARK( create_type<TYPE> ); \
BENCHMARK( add_type<TYPE> ); \
BENCHMARK( multiply_type<TYPE> ); \
BENCHMARK( add_multiply_type<TYPE> ); \
/* BENCHMARK_TYPE */
#if __llvm__
# define BENCHMARK_BIGINT(FUNC) BENCHMARK( FUNC< unsigned _BitInt(128) > )
#else
# define BENCHMARK_BIGINT(FUNC)
#endif
#define BENCHMARK_FUNC(FUNC) \
BENCHMARK( FUNC< boost::multiprecision::uint128_t > ); \
BENCHMARK( FUNC< intx::uint128 > ); \
BENCHMARK( FUNC< absl::uint128 > ); \
BENCHMARK( FUNC< unsigned __int128> ); \
BENCHMARK_BIGINT( FUNC ); \
/* BENCHMARK_FUNC */
BENCHMARK_FUNC(create_type)
BENCHMARK_FUNC(add_type)
BENCHMARK_FUNC(multiply_type)
BENCHMARK_FUNC(add_multiply_type)
BENCHMARK_MAIN();