/ src / bench / poly1305.cpp
poly1305.cpp
 1  // Copyright (c) 2019-present 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  
 6  #include <bench/bench.h>
 7  #include <crypto/poly1305.h>
 8  #include <span.h>
 9  #include <util/byte_units.h>
10  
11  #include <cstddef>
12  #include <cstdint>
13  #include <vector>
14  
15  /* Number of bytes to process per iteration */
16  static constexpr uint64_t BUFFER_SIZE_TINY  = 64;
17  static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
18  static constexpr uint64_t BUFFER_SIZE_LARGE{1_MiB};
19  
20  static void POLY1305(benchmark::Bench& bench, size_t buffersize)
21  {
22      std::vector<std::byte> tag(Poly1305::TAGLEN, {});
23      std::vector<std::byte> key(Poly1305::KEYLEN, {});
24      std::vector<std::byte> in(buffersize, {});
25      bench.batch(in.size()).unit("byte").run([&] {
26          Poly1305{key}.Update(in).Finalize(tag);
27      });
28  }
29  
30  static void POLY1305_64BYTES(benchmark::Bench& bench)
31  {
32      POLY1305(bench, BUFFER_SIZE_TINY);
33  }
34  
35  static void POLY1305_256BYTES(benchmark::Bench& bench)
36  {
37      POLY1305(bench, BUFFER_SIZE_SMALL);
38  }
39  
40  static void POLY1305_1MB(benchmark::Bench& bench)
41  {
42      POLY1305(bench, BUFFER_SIZE_LARGE);
43  }
44  
45  BENCHMARK(POLY1305_64BYTES);
46  BENCHMARK(POLY1305_256BYTES);
47  BENCHMARK(POLY1305_1MB);