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