-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_ntt.cc
58 lines (49 loc) · 1.68 KB
/
benchmark_ntt.cc
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
#include <benchmark/benchmark.h>
#include <memory>
#include <yell/poly.hpp>
#include <nfl/poly.hpp>
constexpr size_t NMod = 4;
class NTT : public ::benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& st) {
yell::ntt<Deg>::init_ntt_tables(NMod); // YELL compute the NTT tables on-fly
p0 = std::make_shared<yell::poly<Deg>>(NMod, yell::uniform{});
p1 = std::make_shared<yell::poly<Deg>>(NMod, yell::uniform{});
_p0 = std::make_shared<nfl::poly<uint64_t, Deg, NMod>>();
_p1 = std::make_shared<nfl::poly<uint64_t, Deg, NMod>>();
for (int cm = 0; cm < NMod; ++cm) {
std::memcpy(_p0->begin() + Deg * cm, p0->cptr_at(cm), sizeof(uint64_t) * Deg);
std::memcpy(_p1->begin() + Deg * cm, p1->cptr_at(cm), sizeof(uint64_t) * Deg);
}
}
void TearDown(const ::benchmark::State& state) {
if (state.thread_index == 0) {
p0.reset();
p1.reset();
_p0.reset();
_p1.reset();
}
}
static constexpr size_t Deg = 8192;
std::shared_ptr<yell::poly<Deg>> p0;
std::shared_ptr<yell::poly<Deg>> p1;
std::shared_ptr<nfl::poly<uint64_t, Deg, NMod>> _p0;
std::shared_ptr<nfl::poly<uint64_t, Deg, NMod>> _p1;
};
BENCHMARK_F(NTT, NFLib_Forward)(benchmark::State& st) {
for (auto _ : st)
_p0->ntt_pow_phi();
}
BENCHMARK_F(NTT, Forward)(benchmark::State& st) {
for (auto _ : st)
p0->forward();
}
BENCHMARK_F(NTT, Backward)(benchmark::State& st) {
for (auto _ : st)
p1->backward();
}
BENCHMARK_F(NTT, NFLib_Backward)(benchmark::State& st) {
for (auto _ : st)
_p1->invntt_pow_invphi();
}
BENCHMARK_MAIN();