-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_limb_add.cpp
More file actions
45 lines (35 loc) · 1.17 KB
/
bench_limb_add.cpp
File metadata and controls
45 lines (35 loc) · 1.17 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
// bench/bench_limb_add.cpp — Benchmark for limb addition routines.
#include <random>
#include <utility>
#include <benchmark/benchmark.h>
#include <t81/core/limb.hpp>
#include <t81/util/random.hpp>
namespace {
inline t81::core::limb random_limb(std::mt19937_64 &rng) {
return t81::util::random_limb(rng);
}
} // namespace
static void
bench_limb_add(benchmark::State &state) {
std::mt19937_64 rng(0x5eedc0de + static_cast<int>(state.thread_index()));
while (state.KeepRunning()) {
const auto lhs = random_limb(rng);
const auto rhs = random_limb(rng);
auto result = lhs + rhs;
benchmark::DoNotOptimize(std::move(result));
}
}
static void
bench_limb_mul(benchmark::State &state) {
std::mt19937_64 rng(0x5eedc0de + static_cast<int>(state.thread_index()) + 0x10);
while (state.KeepRunning()) {
const auto lhs = random_limb(rng);
const auto rhs = random_limb(rng);
auto product = t81::core::limb::mul_wide(lhs, rhs);
auto product_value = product.first;
benchmark::DoNotOptimize(std::move(product_value));
}
}
BENCHMARK(bench_limb_add);
BENCHMARK(bench_limb_mul);
BENCHMARK_MAIN();