-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_numeric_types.cpp
More file actions
71 lines (59 loc) · 2.3 KB
/
bench_numeric_types.cpp
File metadata and controls
71 lines (59 loc) · 2.3 KB
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
// bench/bench_numeric_types.cpp — Benchmarks for the high-level numeric helpers in t81.
#include <benchmark/benchmark.h>
#include <utility>
#include <t81/t81lib.hpp>
namespace {
namespace core = t81::core;
static core::limb make_limb(int value) {
return core::limb::from_value(value);
}
static void BM_FloatMultiply(benchmark::State &state) {
const t81::Float lhs(make_limb(27), 5);
const t81::Float rhs(make_limb(9), -2);
for (auto _ : state) {
auto product = lhs * rhs;
auto mantissa_value = product.mantissa();
benchmark::DoNotOptimize(std::move(mantissa_value));
auto exponent_value = product.exponent();
benchmark::DoNotOptimize(std::move(exponent_value));
}
}
BENCHMARK(BM_FloatMultiply);
static void BM_RatioArithmetic(benchmark::State &state) {
const t81::Ratio lhs(make_limb(63));
const t81::Ratio rhs(make_limb(14));
for (auto _ : state) {
auto sum = lhs + rhs;
auto ordering = lhs <=> rhs;
auto numerator_value = sum.numerator();
benchmark::DoNotOptimize(std::move(numerator_value));
benchmark::DoNotOptimize(std::move(ordering));
}
}
BENCHMARK(BM_RatioArithmetic);
static void BM_MontgomeryIntAdd(benchmark::State &state) {
const t81::Modulus modulus(make_limb(101));
const t81::MontgomeryInt left(modulus, make_limb(33));
const t81::MontgomeryInt right(modulus, make_limb(58));
for (auto _ : state) {
auto result = left;
result += right;
auto limb_value = result.to_limb();
benchmark::DoNotOptimize(std::move(limb_value));
}
}
BENCHMARK(BM_MontgomeryIntAdd);
static void BM_MontgomeryIntMultiply(benchmark::State &state) {
const t81::Modulus modulus(make_limb(101));
const t81::MontgomeryInt left(modulus, make_limb(7));
const t81::MontgomeryInt right(modulus, make_limb(13));
for (auto _ : state) {
auto result = left;
result *= right;
auto limb_value = result.to_limb();
benchmark::DoNotOptimize(std::move(limb_value));
}
}
BENCHMARK(BM_MontgomeryIntMultiply);
} // namespace
BENCHMARK_MAIN();