Skip to content

Commit 69b3a6d

Browse files
committed
Merge #8039: bench: Add crypto hash benchmarks
32114dd bench: Add crypto hash benchmarks (Wladimir J. van der Laan)
2 parents 423ca30 + 32114dd commit 69b3a6d

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/Makefile.bench.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ bench_bench_bitcoin_SOURCES = \
88
bench/bench.cpp \
99
bench/bench.h \
1010
bench/Examples.cpp \
11-
bench/rollingbloom.cpp
11+
bench/rollingbloom.cpp \
12+
bench/crypto_hash.cpp
1213

1314
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
1415
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/bench/crypto_hash.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2016 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 <iostream>
6+
7+
#include "bench.h"
8+
#include "bloom.h"
9+
#include "utiltime.h"
10+
#include "crypto/ripemd160.h"
11+
#include "crypto/sha1.h"
12+
#include "crypto/sha256.h"
13+
#include "crypto/sha512.h"
14+
15+
/* Number of bytes to hash per iteration */
16+
static const uint64_t BUFFER_SIZE = 1000*1000;
17+
18+
static void RIPEMD160(benchmark::State& state)
19+
{
20+
uint8_t hash[CRIPEMD160::OUTPUT_SIZE];
21+
std::vector<uint8_t> in(BUFFER_SIZE,0);
22+
while (state.KeepRunning())
23+
CRIPEMD160().Write(begin_ptr(in), in.size()).Finalize(hash);
24+
}
25+
26+
static void SHA1(benchmark::State& state)
27+
{
28+
uint8_t hash[CSHA1::OUTPUT_SIZE];
29+
std::vector<uint8_t> in(BUFFER_SIZE,0);
30+
while (state.KeepRunning())
31+
CSHA1().Write(begin_ptr(in), in.size()).Finalize(hash);
32+
}
33+
34+
static void SHA256(benchmark::State& state)
35+
{
36+
uint8_t hash[CSHA256::OUTPUT_SIZE];
37+
std::vector<uint8_t> in(BUFFER_SIZE,0);
38+
while (state.KeepRunning())
39+
CSHA256().Write(begin_ptr(in), in.size()).Finalize(hash);
40+
}
41+
42+
static void SHA512(benchmark::State& state)
43+
{
44+
uint8_t hash[CSHA512::OUTPUT_SIZE];
45+
std::vector<uint8_t> in(BUFFER_SIZE,0);
46+
while (state.KeepRunning())
47+
CSHA512().Write(begin_ptr(in), in.size()).Finalize(hash);
48+
}
49+
50+
BENCHMARK(RIPEMD160);
51+
BENCHMARK(SHA1);
52+
BENCHMARK(SHA256);
53+
BENCHMARK(SHA512);

0 commit comments

Comments
 (0)