diff options
Diffstat (limited to 'src/bench')
-rw-r--r-- | src/bench/crypto_hash.cpp | 127 |
1 files changed, 121 insertions, 6 deletions
diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index cf8d807d7b..1685a120b4 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -13,6 +13,7 @@ #include <crypto/siphash.h> #include <hash.h> #include <random.h> +#include <tinyformat.h> #include <uint256.h> /* Number of bytes to hash per iteration */ @@ -36,13 +37,48 @@ static void SHA1(benchmark::Bench& bench) }); } -static void SHA256(benchmark::Bench& bench) +static void SHA256_STANDARD(benchmark::Bench& bench) { + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector<uint8_t> in(BUFFER_SIZE,0); bench.batch(in.size()).unit("byte").run([&] { CSHA256().Write(in.data(), in.size()).Finalize(hash); }); + SHA256AutoDetect(); +} + +static void SHA256_SSE4(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector<uint8_t> in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); + }); + SHA256AutoDetect(); +} + +static void SHA256_AVX2(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector<uint8_t> in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); + }); + SHA256AutoDetect(); +} + +static void SHA256_SHANI(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); + uint8_t hash[CSHA256::OUTPUT_SIZE]; + std::vector<uint8_t> in(BUFFER_SIZE,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256().Write(in.data(), in.size()).Finalize(hash); + }); + SHA256AutoDetect(); } static void SHA3_256_1M(benchmark::Bench& bench) @@ -54,22 +90,92 @@ static void SHA3_256_1M(benchmark::Bench& bench) }); } -static void SHA256_32b(benchmark::Bench& bench) +static void SHA256_32b_STANDARD(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); + std::vector<uint8_t> in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); + }); + SHA256AutoDetect(); +} + +static void SHA256_32b_SSE4(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); + std::vector<uint8_t> in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); + }); + SHA256AutoDetect(); +} + +static void SHA256_32b_AVX2(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); + std::vector<uint8_t> in(32,0); + bench.batch(in.size()).unit("byte").run([&] { + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); + }); + SHA256AutoDetect(); +} + +static void SHA256_32b_SHANI(benchmark::Bench& bench) { + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); std::vector<uint8_t> in(32,0); bench.batch(in.size()).unit("byte").run([&] { CSHA256() .Write(in.data(), in.size()) .Finalize(in.data()); }); + SHA256AutoDetect(); +} + +static void SHA256D64_1024_STANDARD(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::STANDARD))); + std::vector<uint8_t> in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); + }); + SHA256AutoDetect(); +} + +static void SHA256D64_1024_SSE4(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4))); + std::vector<uint8_t> in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); + }); + SHA256AutoDetect(); +} + +static void SHA256D64_1024_AVX2(benchmark::Bench& bench) +{ + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_AVX2))); + std::vector<uint8_t> in(64 * 1024, 0); + bench.batch(in.size()).unit("byte").run([&] { + SHA256D64(in.data(), in.data(), 1024); + }); + SHA256AutoDetect(); } -static void SHA256D64_1024(benchmark::Bench& bench) +static void SHA256D64_1024_SHANI(benchmark::Bench& bench) { + bench.name(strprintf("%s using the '%s' SHA256 implementation", __func__, SHA256AutoDetect(sha256_implementation::USE_SSE4_AND_SHANI))); std::vector<uint8_t> in(64 * 1024, 0); bench.batch(in.size()).unit("byte").run([&] { SHA256D64(in.data(), in.data(), 1024); }); + SHA256AutoDetect(); } static void SHA512(benchmark::Bench& bench) @@ -152,13 +258,22 @@ static void MuHashPrecompute(benchmark::Bench& bench) BENCHMARK(BenchRIPEMD160, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA1, benchmark::PriorityLevel::HIGH); -BENCHMARK(SHA256, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_STANDARD, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_SSE4, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_AVX2, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_SHANI, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA512, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA3_256_1M, benchmark::PriorityLevel::HIGH); -BENCHMARK(SHA256_32b, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_32b_STANDARD, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_32b_SSE4, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_32b_AVX2, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256_32b_SHANI, benchmark::PriorityLevel::HIGH); BENCHMARK(SipHash_32b, benchmark::PriorityLevel::HIGH); -BENCHMARK(SHA256D64_1024, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256D64_1024_STANDARD, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256D64_1024_SSE4, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256D64_1024_AVX2, benchmark::PriorityLevel::HIGH); +BENCHMARK(SHA256D64_1024_SHANI, benchmark::PriorityLevel::HIGH); BENCHMARK(FastRandom_32bit, benchmark::PriorityLevel::HIGH); BENCHMARK(FastRandom_1bit, benchmark::PriorityLevel::HIGH); |