Changeset View
Changeset View
Standalone View
Standalone View
src/bench/crypto_hash.cpp
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <crypto/ripemd160.h> | #include <crypto/ripemd160.h> | ||||
#include <crypto/sha1.h> | #include <crypto/sha1.h> | ||||
#include <crypto/sha256.h> | #include <crypto/sha256.h> | ||||
#include <crypto/sha3.h> | |||||
#include <crypto/sha512.h> | #include <crypto/sha512.h> | ||||
#include <crypto/siphash.h> | #include <crypto/siphash.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <string> | #include <string> | ||||
Show All 19 Lines | |||||
static void SHA256(benchmark::State &state) { | static void SHA256(benchmark::State &state) { | ||||
uint8_t hash[CSHA256::OUTPUT_SIZE]; | uint8_t hash[CSHA256::OUTPUT_SIZE]; | ||||
std::vector<uint8_t> in(BUFFER_SIZE, 0); | std::vector<uint8_t> in(BUFFER_SIZE, 0); | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
CSHA256().Write(in.data(), in.size()).Finalize(hash); | CSHA256().Write(in.data(), in.size()).Finalize(hash); | ||||
} | } | ||||
} | } | ||||
static void SHA3_256_1M(benchmark::State &state) { | |||||
uint8_t hash[SHA3_256::OUTPUT_SIZE]; | |||||
std::vector<uint8_t> in(BUFFER_SIZE, 0); | |||||
while (state.KeepRunning()) { | |||||
SHA3_256().Write(in).Finalize(hash); | |||||
} | |||||
} | |||||
static void SHA256_32b(benchmark::State &state) { | static void SHA256_32b(benchmark::State &state) { | ||||
std::vector<uint8_t> in(32, 0); | std::vector<uint8_t> in(32, 0); | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
CSHA256().Write(in.data(), in.size()).Finalize(in.data()); | CSHA256().Write(in.data(), in.size()).Finalize(in.data()); | ||||
} | } | ||||
} | } | ||||
static void SHA256D64_1024(benchmark::State &state) { | static void SHA256D64_1024(benchmark::State &state) { | ||||
Show All 33 Lines | while (state.KeepRunning()) { | ||||
rng.randbool(); | rng.randbool(); | ||||
} | } | ||||
} | } | ||||
BENCHMARK(RIPEMD160, 440); | BENCHMARK(RIPEMD160, 440); | ||||
BENCHMARK(SHA1, 570); | BENCHMARK(SHA1, 570); | ||||
BENCHMARK(SHA256, 340); | BENCHMARK(SHA256, 340); | ||||
BENCHMARK(SHA512, 330); | BENCHMARK(SHA512, 330); | ||||
BENCHMARK(SHA3_256_1M, 300); | |||||
BENCHMARK(SHA256_32b, 4700 * 1000); | BENCHMARK(SHA256_32b, 4700 * 1000); | ||||
BENCHMARK(SipHash_32b, 40 * 1000 * 1000); | BENCHMARK(SipHash_32b, 40 * 1000 * 1000); | ||||
BENCHMARK(SHA256D64_1024, 7400); | BENCHMARK(SHA256D64_1024, 7400); | ||||
BENCHMARK(FastRandom_32bit, 110 * 1000 * 1000); | BENCHMARK(FastRandom_32bit, 110 * 1000 * 1000); | ||||
BENCHMARK(FastRandom_1bit, 440 * 1000 * 1000); | BENCHMARK(FastRandom_1bit, 440 * 1000 * 1000); |