Bitcoin ABC  0.24.7
P2P Digital Currency
poly1305.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <iostream>
6 
7 #include <bench/bench.h>
8 #include <crypto/poly1305.h>
9 
10 /* Number of bytes to process per iteration */
11 static constexpr uint64_t BUFFER_SIZE_TINY = 64;
12 static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
13 static constexpr uint64_t BUFFER_SIZE_LARGE = 1024 * 1024;
14 
15 static void POLY1305(benchmark::Bench &bench, size_t buffersize) {
16  std::vector<uint8_t> tag(POLY1305_TAGLEN, 0);
17  std::vector<uint8_t> key(POLY1305_KEYLEN, 0);
18  std::vector<uint8_t> in(buffersize, 0);
19  bench.batch(in.size()).unit("byte").run(
20  [&] { poly1305_auth(tag.data(), in.data(), in.size(), key.data()); });
21 }
22 
23 static void POLY1305_64BYTES(benchmark::Bench &bench) {
24  POLY1305(bench, BUFFER_SIZE_TINY);
25 }
26 
27 static void POLY1305_256BYTES(benchmark::Bench &bench) {
29 }
30 
31 static void POLY1305_1MB(benchmark::Bench &bench) {
33 }
34 
ankerl::nanobench::Bench::batch
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
POLY1305_256BYTES
static void POLY1305_256BYTES(benchmark::Bench &bench)
Definition: poly1305.cpp:27
BENCHMARK
BENCHMARK(POLY1305_64BYTES)
POLY1305_1MB
static void POLY1305_1MB(benchmark::Bench &bench)
Definition: poly1305.cpp:31
BUFFER_SIZE_TINY
static constexpr uint64_t BUFFER_SIZE_TINY
Definition: poly1305.cpp:11
poly1305.h
POLY1305_64BYTES
static void POLY1305_64BYTES(benchmark::Bench &bench)
Definition: poly1305.cpp:23
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
POLY1305
static void POLY1305(benchmark::Bench &bench, size_t buffersize)
Definition: poly1305.cpp:15
bench.h
POLY1305_TAGLEN
#define POLY1305_TAGLEN
Definition: poly1305.h:12
POLY1305_KEYLEN
#define POLY1305_KEYLEN
Definition: poly1305.h:11
poly1305_auth
void poly1305_auth(uint8_t out[POLY1305_TAGLEN], const uint8_t *m, size_t inlen, const uint8_t key[POLY1305_KEYLEN])
Definition: poly1305.cpp:15
BUFFER_SIZE_LARGE
static constexpr uint64_t BUFFER_SIZE_LARGE
Definition: poly1305.cpp:13
BUFFER_SIZE_SMALL
static constexpr uint64_t BUFFER_SIZE_SMALL
Definition: poly1305.cpp:12