Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pure_to_radix.bench.cpp
Go to the documentation of this file.
1#include <benchmark/benchmark.h>
2
5
6namespace bb::avm2::simulation {
7
8using namespace benchmark;
9using namespace bb::avm2;
10
11namespace {
12
13void BM_pure_to_radix(State& state)
14{
15 PureToRadix pure_to_radix;
16
17 for (auto _ : state) {
18 state.PauseTiming();
20 uint32_t num_limbs = static_cast<uint32_t>(state.range(0));
21 uint32_t radix = static_cast<uint32_t>(state.range(1));
22 state.ResumeTiming();
23 benchmark::DoNotOptimize(pure_to_radix.to_le_radix(value, num_limbs, radix));
24 }
25}
26
27void BM_pure_to_bits(State& state)
28{
29 PureToRadix pure_to_radix;
30
31 for (auto _ : state) {
32 state.PauseTiming();
34 uint32_t num_limbs = static_cast<uint32_t>(state.range(0));
35 state.ResumeTiming();
36 benchmark::DoNotOptimize(pure_to_radix.to_le_bits(value, num_limbs));
37 }
38}
39
40void BM_pure_to_radix_memory(State& state)
41{
42 PureToRadix pure_to_radix;
43
44 for (auto _ : state) {
45 state.PauseTiming();
47 uint32_t num_limbs = static_cast<uint32_t>(state.range(0));
48 uint32_t radix = static_cast<uint32_t>(state.range(1));
49 // Compute a random value that fits in the limbs to avoid truncation errors
50 uint256_t value = 0;
51 for (uint32_t i = 0; i < num_limbs; i++) {
52 value = value * radix + static_cast<uint32_t>(rand()) % radix;
53 }
54 state.ResumeTiming();
55 pure_to_radix.to_be_radix(memory, value, radix, num_limbs, false, /*dst_addr*/ 0);
56 }
57}
58
59BENCHMARK(BM_pure_to_radix)->Ranges({ { 2, 256 }, { 2, 256 } })->Unit(benchmark::kMillisecond);
60BENCHMARK(BM_pure_to_bits)->Ranges({ { 2, 256 } })->Unit(benchmark::kMillisecond);
61BENCHMARK(BM_pure_to_radix_memory)->Ranges({ { 2, 256 }, { 2, 256 } })->Unit(benchmark::kMillisecond);
62
63} // namespace
64
65} // namespace bb::avm2::simulation
66
void to_be_radix(MemoryInterface &memory, const FF &value, uint32_t radix, uint32_t num_limbs, bool is_output_bits, MemoryAddress dst_addr) override
std::pair< std::vector< bool >, bool > to_le_bits(const FF &value, uint32_t num_limbs) override
std::pair< std::vector< uint8_t >, bool > to_le_radix(const FF &value, uint32_t num_limbs, uint32_t radix) override
Unit(benchmark::kMillisecond) -> RangeMultiplier(2) ->Range(2, MAX_BATCH_SIZE) ->Iterations(1000)
BENCHMARK(extend_2_to_11)
BENCHMARK_MAIN()
static field random_element(numeric::RNG *engine=nullptr) noexcept