aboutsummaryrefslogtreecommitdiff
path: root/src/bench/hashpadding.cpp
diff options
context:
space:
mode:
authorJeremy Rubin <j@rubin.io>2019-07-24 13:36:47 -0700
committerJeremy Rubin <j@rubin.io>2020-04-29 00:31:41 -0700
commit5495fa585007b40b2e9285c23be275de71708af8 (patch)
treee46ef89d048543e474eb534aeec9533737d7deaa /src/bench/hashpadding.cpp
parentba348dbc518b8e082a5dc3a225432fdacf859a13 (diff)
Add Hash Padding Microbenchmarks
Diffstat (limited to 'src/bench/hashpadding.cpp')
-rw-r--r--src/bench/hashpadding.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/bench/hashpadding.cpp b/src/bench/hashpadding.cpp
new file mode 100644
index 0000000000..985be8bdba
--- /dev/null
+++ b/src/bench/hashpadding.cpp
@@ -0,0 +1,47 @@
+// Copyright (c) 2015-2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <bench/bench.h>
+#include <hash.h>
+#include <random.h>
+#include <uint256.h>
+
+
+static void PrePadded(benchmark::State& state)
+{
+
+ CSHA256 hasher;
+
+ // Setup the salted hasher
+ uint256 nonce = GetRandHash();
+ hasher.Write(nonce.begin(), 32);
+ hasher.Write(nonce.begin(), 32);
+ uint256 data = GetRandHash();
+ while (state.KeepRunning()) {
+ unsigned char out[32];
+ CSHA256 h = hasher;
+ h.Write(data.begin(), 32);
+ h.Finalize(out);
+ }
+}
+
+BENCHMARK(PrePadded, 10000);
+
+static void RegularPadded(benchmark::State& state)
+{
+ CSHA256 hasher;
+
+ // Setup the salted hasher
+ uint256 nonce = GetRandHash();
+ uint256 data = GetRandHash();
+ while (state.KeepRunning()) {
+ unsigned char out[32];
+ CSHA256 h = hasher;
+ h.Write(nonce.begin(), 32);
+ h.Write(data.begin(), 32);
+ h.Finalize(out);
+ }
+}
+
+BENCHMARK(RegularPadded, 10000);