Merge #10114: [tests] sync_with_ping should assert that ping hasn't timed out
[bitcoinplatinum.git] / src / bench / crypto_hash.cpp
blob737d3572ae9a23303bddd4159811d2a221307c69
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.
5 #include <iostream>
7 #include "bench.h"
8 #include "bloom.h"
9 #include "hash.h"
10 #include "uint256.h"
11 #include "utiltime.h"
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)
64 uint256 x;
65 while (state.KeepRunning()) {
66 for (int i = 0; i < 1000000; i++) {
67 *((uint64_t*)x.begin()) = SipHashUint256(0, i, x);
72 BENCHMARK(RIPEMD160);
73 BENCHMARK(SHA1);
74 BENCHMARK(SHA256);
75 BENCHMARK(SHA512);
77 BENCHMARK(SHA256_32b);
78 BENCHMARK(SipHash_32b);