diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index 280ad61b13..7f562e7cd9 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -1,58 +1,59 @@ // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include static const int MIN_CORES = 2; static const size_t BATCHES = 101; static const size_t BATCH_SIZE = 30; static const int PREVECTOR_SIZE = 28; static const size_t QUEUE_BATCH_SIZE = 128; // This Benchmark tests the CheckQueue with a slightly realistic workload, where // checks all contain a prevector that is indirect 50% of the time and there is // a little bit of work done between calls to Add. static void CCheckQueueSpeedPrevectorJob(benchmark::State &state) { struct PrevectorJob { prevector p; PrevectorJob() {} explicit PrevectorJob(FastRandomContext &insecure_rand) { p.resize(insecure_rand.randrange(PREVECTOR_SIZE * 2)); } bool operator()() { return true; } void swap(PrevectorJob &x) { p.swap(x.p); }; }; CCheckQueue queue{QUEUE_BATCH_SIZE}; boost::thread_group tg; for (auto x = 0; x < std::max(MIN_CORES, GetNumCores()); ++x) { tg.create_thread([&] { queue.Thread(); }); } while (state.KeepRunning()) { // Make insecure_rand here so that each iteration is identical. FastRandomContext insecure_rand(true); CCheckQueueControl control(&queue); std::vector> vBatches(BATCHES); for (auto &vChecks : vBatches) { vChecks.reserve(BATCH_SIZE); - for (size_t x = 0; x < BATCH_SIZE; ++x) + for (size_t x = 0; x < BATCH_SIZE; ++x) { vChecks.emplace_back(insecure_rand); + } control.Add(vChecks); } // control waits for completion by RAII, but it is done explicitly here // for clarity control.Wait(); } tg.interrupt_all(); tg.join_all(); } BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400); diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 063b9fe245..774147951c 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -1,97 +1,101 @@ // Copyright (c) 2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include #include #include #include #include /* Number of bytes to hash per iteration */ static const uint64_t BUFFER_SIZE = 1000 * 1000; static void RIPEMD160(benchmark::State &state) { uint8_t hash[CRIPEMD160::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE, 0); - while (state.KeepRunning()) + while (state.KeepRunning()) { CRIPEMD160().Write(in.data(), in.size()).Finalize(hash); + } } static void SHA1(benchmark::State &state) { uint8_t hash[CSHA1::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE, 0); - while (state.KeepRunning()) + while (state.KeepRunning()) { CSHA1().Write(in.data(), in.size()).Finalize(hash); + } } static void SHA256(benchmark::State &state) { uint8_t hash[CSHA256::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE, 0); - while (state.KeepRunning()) + while (state.KeepRunning()) { CSHA256().Write(in.data(), in.size()).Finalize(hash); + } } static void SHA256_32b(benchmark::State &state) { std::vector in(32, 0); while (state.KeepRunning()) { CSHA256().Write(in.data(), in.size()).Finalize(in.data()); } } static void SHA256D64_1024(benchmark::State &state) { std::vector in(64 * 1024, 0); while (state.KeepRunning()) { SHA256D64(in.data(), in.data(), 1024); } } static void SHA512(benchmark::State &state) { uint8_t hash[CSHA512::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE, 0); - while (state.KeepRunning()) + while (state.KeepRunning()) { CSHA512().Write(in.data(), in.size()).Finalize(hash); + } } static void SipHash_32b(benchmark::State &state) { uint256 x; uint64_t k1 = 0; while (state.KeepRunning()) { uint64_t hash64 = SipHashUint256(0, ++k1, x); std::memcpy(x.begin(), &hash64, sizeof(hash64)); } } static void FastRandom_32bit(benchmark::State &state) { FastRandomContext rng(true); while (state.KeepRunning()) { rng.rand32(); } } static void FastRandom_1bit(benchmark::State &state) { FastRandomContext rng(true); while (state.KeepRunning()) { rng.randbool(); } } BENCHMARK(RIPEMD160, 440); BENCHMARK(SHA1, 570); BENCHMARK(SHA256, 340); BENCHMARK(SHA512, 330); BENCHMARK(SHA256_32b, 4700 * 1000); BENCHMARK(SipHash_32b, 40 * 1000 * 1000); BENCHMARK(SHA256D64_1024, 7400); BENCHMARK(FastRandom_32bit, 110 * 1000 * 1000); BENCHMARK(FastRandom_1bit, 440 * 1000 * 1000); diff --git a/src/bench/lockedpool.cpp b/src/bench/lockedpool.cpp index 49d161300d..9d215eb6a3 100644 --- a/src/bench/lockedpool.cpp +++ b/src/bench/lockedpool.cpp @@ -1,44 +1,48 @@ // Copyright (c) 2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #define ASIZE 2048 #define BITER 5000 #define MSIZE 2048 static void BenchLockedPool(benchmark::State &state) { void *synth_base = reinterpret_cast(0x08000000); const size_t synth_size = 1024 * 1024; Arena b(synth_base, synth_size, 16); std::vector addr; - for (int x = 0; x < ASIZE; ++x) + for (int x = 0; x < ASIZE; ++x) { addr.push_back(nullptr); + } uint32_t s = 0x12345678; while (state.KeepRunning()) { for (int x = 0; x < BITER; ++x) { int idx = s & (addr.size() - 1); if (s & 0x80000000) { b.free(addr[idx]); addr[idx] = nullptr; } else if (!addr[idx]) { addr[idx] = b.alloc((s >> 16) & (MSIZE - 1)); } bool lsb = s & 1; s >>= 1; - if (lsb) s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0 + if (lsb) { + s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0 + } } } - for (void *ptr : addr) + for (void *ptr : addr) { b.free(ptr); + } addr.clear(); } BENCHMARK(BenchLockedPool, 1300);