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.
12 #include "crypto/ripemd160.h"
13 #include "crypto/sha1.h"
14 #include "crypto/sha256.h"
15 #include "crypto/sha512.h"
17 /* Number of bytes to hash per iteration */
18 static const uint64_t BUFFER_SIZE
= 1000*1000;
20 static void RIPEMD160(benchmark::State
& state
)
22 uint8_t hash
[CRIPEMD160::OUTPUT_SIZE
];
23 std::vector
<uint8_t> in(BUFFER_SIZE
,0);
24 while (state
.KeepRunning())
25 CRIPEMD160().Write(in
.data(), in
.size()).Finalize(hash
);
28 static void SHA1(benchmark::State
& state
)
30 uint8_t hash
[CSHA1::OUTPUT_SIZE
];
31 std::vector
<uint8_t> in(BUFFER_SIZE
,0);
32 while (state
.KeepRunning())
33 CSHA1().Write(in
.data(), in
.size()).Finalize(hash
);
36 static void SHA256(benchmark::State
& state
)
38 uint8_t hash
[CSHA256::OUTPUT_SIZE
];
39 std::vector
<uint8_t> in(BUFFER_SIZE
,0);
40 while (state
.KeepRunning())
41 CSHA256().Write(in
.data(), in
.size()).Finalize(hash
);
44 static void SHA256_32b(benchmark::State
& state
)
46 std::vector
<uint8_t> in(32,0);
47 while (state
.KeepRunning()) {
48 for (int i
= 0; i
< 1000000; i
++) {
49 CSHA256().Write(in
.data(), in
.size()).Finalize(&in
[0]);
54 static void SHA512(benchmark::State
& state
)
56 uint8_t hash
[CSHA512::OUTPUT_SIZE
];
57 std::vector
<uint8_t> in(BUFFER_SIZE
,0);
58 while (state
.KeepRunning())
59 CSHA512().Write(in
.data(), in
.size()).Finalize(hash
);
62 static void SipHash_32b(benchmark::State
& state
)
65 while (state
.KeepRunning()) {
66 for (int i
= 0; i
< 1000000; i
++) {
67 *((uint64_t*)x
.begin()) = SipHashUint256(0, i
, x
);
77 BENCHMARK(SHA256_32b
);
78 BENCHMARK(SipHash_32b
);