diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-12-23 14:46:20 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-12-23 14:53:05 +0100 |
commit | 5180a86c96bc05d2a731f70f36aae28ab5a3fad4 (patch) | |
tree | 2339b7b14ec174861d1baa73a44a33680644f820 /src/bench/crypto_hash.cpp | |
parent | 20166f8a448156f476f3e23825f59ebec36424a9 (diff) | |
parent | 760af84072408ba53d009e868fccc25fb186d40c (diff) | |
download | bitcoin-5180a86c96bc05d2a731f70f36aae28ab5a3fad4.tar.xz |
Merge #11517: Tests: Improve benchmark precision
760af84 Removed CCheckQueueSpeed benchmark (Martin Ankerl)
00721e6 Improved microbenchmarking with multiple features. (Martin Ankerl)
Pull request description:
The benchmark's KeepRunning() used to make a function call for each call, inflating measurement times for short running code. This change inlines the critical code that is executed each run and moves the slow timer updates into a new function.
This change increases the average runtime for Trig from 0.000000082339208 sec to 0.000000080948591.
Tree-SHA512: 36b3bc55fc9b1d4cbf526b7103af6af18e9783e6b8f3ad3adbd09fac0bf9401cfefad58fd1e6fa2615d3c4e677998f912f3323d61d7b00b1c660d581c257d577
Diffstat (limited to 'src/bench/crypto_hash.cpp')
-rw-r--r-- | src/bench/crypto_hash.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index b37b5cad62..bb89718074 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -46,9 +46,9 @@ static void SHA256_32b(benchmark::State& state) { std::vector<uint8_t> in(32,0); while (state.KeepRunning()) { - for (int i = 0; i < 1000000; i++) { - CSHA256().Write(in.data(), in.size()).Finalize(in.data()); - } + CSHA256() + .Write(in.data(), in.size()) + .Finalize(in.data()); } } @@ -63,10 +63,9 @@ static void SHA512(benchmark::State& state) static void SipHash_32b(benchmark::State& state) { uint256 x; + uint64_t k1 = 0; while (state.KeepRunning()) { - for (int i = 0; i < 1000000; i++) { - *((uint64_t*)x.begin()) = SipHashUint256(0, i, x); - } + *((uint64_t*)x.begin()) = SipHashUint256(0, ++k1, x); } } @@ -75,9 +74,7 @@ static void FastRandom_32bit(benchmark::State& state) FastRandomContext rng(true); uint32_t x = 0; while (state.KeepRunning()) { - for (int i = 0; i < 1000000; i++) { - x += rng.rand32(); - } + x += rng.rand32(); } } @@ -86,18 +83,16 @@ static void FastRandom_1bit(benchmark::State& state) FastRandomContext rng(true); uint32_t x = 0; while (state.KeepRunning()) { - for (int i = 0; i < 1000000; i++) { - x += rng.randbool(); - } + x += rng.randbool(); } } -BENCHMARK(RIPEMD160); -BENCHMARK(SHA1); -BENCHMARK(SHA256); -BENCHMARK(SHA512); +BENCHMARK(RIPEMD160, 440); +BENCHMARK(SHA1, 570); +BENCHMARK(SHA256, 340); +BENCHMARK(SHA512, 330); -BENCHMARK(SHA256_32b); -BENCHMARK(SipHash_32b); -BENCHMARK(FastRandom_32bit); -BENCHMARK(FastRandom_1bit); +BENCHMARK(SHA256_32b, 4700 * 1000); +BENCHMARK(SipHash_32b, 40 * 1000 * 1000); +BENCHMARK(FastRandom_32bit, 110 * 1000 * 1000); +BENCHMARK(FastRandom_1bit, 440 * 1000 * 1000); |