Changeset View
Changeset View
Standalone View
Standalone View
src/bench/hashpadding.cpp
// Copyright (c) 2015-2018 The Bitcoin Core developers | // Copyright (c) 2015-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
static void PrePadded(benchmark::State &state) { | static void PrePadded(benchmark::Bench &bench) { | ||||
CSHA256 hasher; | CSHA256 hasher; | ||||
// Setup the salted hasher | // Setup the salted hasher | ||||
uint256 nonce = GetRandHash(); | uint256 nonce = GetRandHash(); | ||||
hasher.Write(nonce.begin(), 32); | hasher.Write(nonce.begin(), 32); | ||||
hasher.Write(nonce.begin(), 32); | hasher.Write(nonce.begin(), 32); | ||||
uint256 data = GetRandHash(); | uint256 data = GetRandHash(); | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
uint8_t out[32]; | uint8_t out[32]; | ||||
CSHA256 h = hasher; | CSHA256 h = hasher; | ||||
h.Write(data.begin(), 32); | h.Write(data.begin(), 32); | ||||
h.Finalize(out); | h.Finalize(out); | ||||
} | }); | ||||
} | } | ||||
BENCHMARK(PrePadded, 10000); | BENCHMARK(PrePadded); | ||||
static void RegularPadded(benchmark::State &state) { | static void RegularPadded(benchmark::Bench &bench) { | ||||
CSHA256 hasher; | CSHA256 hasher; | ||||
// Setup the salted hasher | // Setup the salted hasher | ||||
uint256 nonce = GetRandHash(); | uint256 nonce = GetRandHash(); | ||||
uint256 data = GetRandHash(); | uint256 data = GetRandHash(); | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
uint8_t out[32]; | uint8_t out[32]; | ||||
CSHA256 h = hasher; | CSHA256 h = hasher; | ||||
h.Write(nonce.begin(), 32); | h.Write(nonce.begin(), 32); | ||||
h.Write(data.begin(), 32); | h.Write(data.begin(), 32); | ||||
h.Finalize(out); | h.Finalize(out); | ||||
} | }); | ||||
} | } | ||||
BENCHMARK(RegularPadded, 10000); | BENCHMARK(RegularPadded); |