Bitcoin ABC  0.24.10
P2P Digital Currency
hashpadding.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2018 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 <bench/bench.h>
6 #include <hash.h>
7 #include <random.h>
8 #include <uint256.h>
9 
10 static void PrePadded(benchmark::Bench &bench) {
11  CSHA256 hasher;
12 
13  // Setup the salted hasher
14  uint256 nonce = GetRandHash();
15  hasher.Write(nonce.begin(), 32);
16  hasher.Write(nonce.begin(), 32);
17  uint256 data = GetRandHash();
18  bench.run([&] {
19  uint8_t out[32];
20  CSHA256 h = hasher;
21  h.Write(data.begin(), 32);
22  h.Finalize(out);
23  });
24 }
25 
27 
28 static void RegularPadded(benchmark::Bench &bench) {
29  CSHA256 hasher;
30 
31  // Setup the salted hasher
32  uint256 nonce = GetRandHash();
33  uint256 data = GetRandHash();
34  bench.run([&] {
35  uint8_t out[32];
36  CSHA256 h = hasher;
37  h.Write(nonce.begin(), 32);
38  h.Write(data.begin(), 32);
39  h.Finalize(out);
40  });
41 }
42 
RegularPadded
static void RegularPadded(benchmark::Bench &bench)
Definition: hashpadding.cpp:28
uint256.h
BENCHMARK
BENCHMARK(PrePadded)
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
random.h
CSHA256::Finalize
void Finalize(uint8_t hash[OUTPUT_SIZE])
Definition: sha256.cpp:844
GetRandHash
uint256 GetRandHash() noexcept
Definition: random.cpp:658
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
uint256
256-bit opaque blob.
Definition: uint256.h:127
bench.h
base_blob::begin
uint8_t * begin()
Definition: uint256.h:83
CSHA256
A hasher class for SHA-256.
Definition: sha256.h:13
PrePadded
static void PrePadded(benchmark::Bench &bench)
Definition: hashpadding.cpp:10
CSHA256::Write
CSHA256 & Write(const uint8_t *data, size_t len)
Definition: sha256.cpp:819