Bitcoin ABC 0.30.5
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
10static 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
28static 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
A hasher class for SHA-256.
Definition: sha256.h:13
CSHA256 & Write(const uint8_t *data, size_t len)
Definition: sha256.cpp:819
void Finalize(uint8_t hash[OUTPUT_SIZE])
Definition: sha256.cpp:844
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
uint8_t * begin()
Definition: uint256.h:85
256-bit opaque blob.
Definition: uint256.h:129
static void PrePadded(benchmark::Bench &bench)
Definition: hashpadding.cpp:10
static void RegularPadded(benchmark::Bench &bench)
Definition: hashpadding.cpp:28
BENCHMARK(PrePadded)
uint256 GetRandHash() noexcept
Definition: random.cpp:659