poulpy/spqlios/lib/test/spqlios_q120_ntt_bench.cpp
spqlios/lib/test/spqlios_q120_ntt_bench.cppRaw
1#include <benchmark/benchmark.h>
2
3#include <cstdint>
4
5#include "spqlios/q120/q120_ntt.h"
6
7#define ARGS Arg(1 << 10)->Arg(1 << 11)->Arg(1 << 12)->Arg(1 << 13)->Arg(1 << 14)->Arg(1 << 15)->Arg(1 << 16)
8
9template <typeof(q120_ntt_bb_avx2) f>
10void benchmark_ntt(benchmark::State& state) {
11 const uint64_t n = state.range(0);
12 q120_ntt_precomp* precomp = q120_new_ntt_bb_precomp(n);
13
14 uint64_t* px = new uint64_t[n * 4];
15 for (uint64_t i = 0; i < 4 * n; i++) {
16 px[i] = (rand() << 31) + rand();
17 }
18 for (auto _ : state) {
19 f(precomp, (q120b*)px);
20 }
21 delete[] px;
22 q120_del_ntt_bb_precomp(precomp);
23}
24
25template <typeof(q120_intt_bb_avx2) f>
26void benchmark_intt(benchmark::State& state) {
27 const uint64_t n = state.range(0);
28 q120_ntt_precomp* precomp = q120_new_intt_bb_precomp(n);
29
30 uint64_t* px = new uint64_t[n * 4];
31 for (uint64_t i = 0; i < 4 * n; i++) {
32 px[i] = (rand() << 31) + rand();
33 }
34 for (auto _ : state) {
35 f(precomp, (q120b*)px);
36 }
37 delete[] px;
38 q120_del_intt_bb_precomp(precomp);
39}
40
41BENCHMARK(benchmark_ntt<q120_ntt_bb_avx2>)->Name("q120_ntt_bb_avx2")->ARGS;
42BENCHMARK(benchmark_intt<q120_intt_bb_avx2>)->Name("q120_intt_bb_avx2")->ARGS;
43
44BENCHMARK_MAIN();