|
| 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