Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
fr_straight.bench.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "fr.hpp"
8
9#include <benchmark/benchmark.h>
10
11using namespace bb;
12using namespace benchmark;
13
14#ifndef DISABLE_ASM
15namespace {
16void asm_add_with_coarse_reduction(State& state) noexcept
17{
18 fr x, y;
19 for (auto _ : state) {
20 DoNotOptimize(fr::asm_add_with_coarse_reduction(x, y));
21 }
22}
23BENCHMARK(asm_add_with_coarse_reduction);
24
25void asm_conditional_negate(State& state) noexcept
26{
27 fr x;
28 for (auto _ : state) {
29 fr::asm_conditional_negate(x, true);
30 }
31}
32BENCHMARK(asm_conditional_negate);
33
34void asm_mul_with_coarse_reduction(State& state) noexcept
35{
36 fr x, y;
37 for (auto _ : state) {
38 DoNotOptimize(fr::asm_mul_with_coarse_reduction(x, y));
39 }
40}
41BENCHMARK(asm_mul_with_coarse_reduction);
42
43void asm_reduce_once(State& state) noexcept
44{
45 fr x;
46 for (auto _ : state) {
47 DoNotOptimize(fr::asm_reduce_once(x));
48 }
49}
50BENCHMARK(asm_reduce_once);
51
52void asm_self_add_with_coarse_reduction(State& state) noexcept
53{
54 fr x, y;
55 for (auto _ : state) {
56 fr::asm_self_add_with_coarse_reduction(x, y);
57 }
58}
59BENCHMARK(asm_self_add_with_coarse_reduction);
60
61void asm_self_mul_with_coarse_reduction(State& state) noexcept
62{
63 fr x, y;
64 for (auto _ : state) {
65 fr::asm_self_mul_with_coarse_reduction(x, y);
66 }
67}
68BENCHMARK(asm_self_mul_with_coarse_reduction);
69
70void asm_self_reduce_once(State& state) noexcept
71{
72 fr x;
73 for (auto _ : state) {
74 fr::asm_self_reduce_once(x);
75 }
76}
77BENCHMARK(asm_self_reduce_once);
78
79void asm_self_sqr_with_coarse_reduction(State& state) noexcept
80{
81 fr x;
82 for (auto _ : state) {
83 fr::asm_self_sqr_with_coarse_reduction(x);
84 }
85}
86BENCHMARK(asm_self_sqr_with_coarse_reduction);
87
88void asm_self_sub_with_coarse_reduction(State& state) noexcept
89{
90 fr x, y;
91 for (auto _ : state) {
92 fr::asm_self_sub_with_coarse_reduction(x, y);
93 }
94}
95BENCHMARK(asm_self_sub_with_coarse_reduction);
96
97void asm_sqr_with_coarse_reduction(State& state) noexcept
98{
99 fr x;
100 for (auto _ : state) {
101 DoNotOptimize(fr::asm_sqr_with_coarse_reduction(x));
102 }
103}
104BENCHMARK(asm_sqr_with_coarse_reduction);
105
106void mul(State& state) noexcept
107{
108 fr x, y;
109 for (auto _ : state) {
110 DoNotOptimize(x * y);
111 }
112}
113BENCHMARK(mul);
114
115void self_mul(State& state) noexcept
116{
117 fr x, y;
118 for (auto _ : state) {
119 x *= y;
120 }
121}
122BENCHMARK(self_mul);
123
124void add(State& state) noexcept
125{
126 fr x, y;
127 for (auto _ : state) {
128 DoNotOptimize(x + y);
129 }
130}
131BENCHMARK(add);
132
133void self_add(State& state) noexcept
134{
135 fr x, y;
136 for (auto _ : state) {
137 x += y;
138 }
139}
140BENCHMARK(self_add);
141
142void sub(State& state) noexcept
143{
144 fr x, y;
145 for (auto _ : state) {
146 DoNotOptimize(x - y);
147 }
148}
149BENCHMARK(sub);
150
151void self_sub(State& state) noexcept
152{
153 fr x, y;
154 for (auto _ : state) {
155 x -= y;
156 }
157}
158BENCHMARK(self_sub);
159
160void invert(State& state) noexcept
161{
162 fr x;
163 for (auto _ : state) {
164 DoNotOptimize(x.invert());
165 }
166}
167BENCHMARK(invert);
168
169void self_neg(State& state) noexcept
170{
171 fr x;
172 for (auto _ : state) {
173 x.self_neg();
174 }
175}
176BENCHMARK(self_neg);
177
178void self_reduce_once(State& state) noexcept
179{
180 fr x;
181 for (auto _ : state) {
183 }
184}
185BENCHMARK(self_reduce_once);
186
187void self_to_montgomery_form(State& state) noexcept
188{
189 fr x;
190 for (auto _ : state) {
192 }
193}
194BENCHMARK(self_to_montgomery_form);
195
196void self_sqr(State& state) noexcept
197{
198 fr x;
199 for (auto _ : state) {
200 x.self_sqr();
201 }
202}
203BENCHMARK(self_sqr);
204
205void sqr(State& state) noexcept
206{
207 fr x;
208 for (auto _ : state) {
209 DoNotOptimize(x.sqr());
210 }
211}
212BENCHMARK(sqr);
213} // namespace
214#endif
215
216// NOLINTNEXTLINE macro invocation triggers style guideline errors from googletest code
BENCHMARK_MAIN()
Entry point for Barretenberg command-line interface.
BENCHMARK(vector_of_evaluations) -> DenseRange(15, 21) ->Unit(kMillisecond) ->Iterations(1)
BB_INLINE constexpr void self_reduce_once() &noexcept
BB_INLINE constexpr void self_sqr() &noexcept
constexpr field invert() const noexcept
BB_INLINE constexpr void self_neg() &noexcept
BB_INLINE constexpr field sqr() const noexcept
BB_INLINE constexpr void self_to_montgomery_form() &noexcept