From 810c2dc769291949ef95ff4c63220ea1b67d15fe Mon Sep 17 00:00:00 2001 From: dergoegge Date: Fri, 25 Oct 2024 15:04:45 +0100 Subject: [PATCH 1/2] [bench] Remove various extraneous benchmarks --- src/bench/CMakeLists.txt | 9 -- src/bench/addrman.cpp | 183 ------------------------------------ src/bench/base58.cpp | 56 ----------- src/bench/bech32.cpp | 35 ------- src/bench/descriptors.cpp | 37 -------- src/bench/logging.cpp | 64 ------------- src/bench/parse_hex.cpp | 36 ------- src/bench/peer_eviction.cpp | 154 ------------------------------ src/bench/strencodings.cpp | 21 ----- src/bench/util_time.cpp | 42 --------- 10 files changed, 637 deletions(-) delete mode 100644 src/bench/addrman.cpp delete mode 100644 src/bench/base58.cpp delete mode 100644 src/bench/bech32.cpp delete mode 100644 src/bench/descriptors.cpp delete mode 100644 src/bench/logging.cpp delete mode 100644 src/bench/parse_hex.cpp delete mode 100644 src/bench/peer_eviction.cpp delete mode 100644 src/bench/strencodings.cpp delete mode 100644 src/bench/util_time.cpp diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index 4589ef177c..b9c977bee6 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -11,9 +11,6 @@ add_executable(bench_bitcoin nanobench.cpp ${CMAKE_CURRENT_BINARY_DIR}/data/block413567.raw.h # Benchmarks: - addrman.cpp - base58.cpp - bech32.cpp bip324_ecdh.cpp block_assemble.cpp ccoins_caching.cpp @@ -23,7 +20,6 @@ add_executable(bench_bitcoin checkqueue.cpp cluster_linearize.cpp crypto_hash.cpp - descriptors.cpp disconnected_transactions.cpp duplicate_inputs.cpp ellswift.cpp @@ -33,13 +29,10 @@ add_executable(bench_bitcoin index_blockfilter.cpp load_external.cpp lockedpool.cpp - logging.cpp mempool_ephemeral_spends.cpp mempool_eviction.cpp mempool_stress.cpp merkle_root.cpp - parse_hex.cpp - peer_eviction.cpp poly1305.cpp pool.cpp prevector.cpp @@ -50,8 +43,6 @@ add_executable(bench_bitcoin rpc_mempool.cpp sign_transaction.cpp streams_findbyte.cpp - strencodings.cpp - util_time.cpp verify_script.cpp xor.cpp ) diff --git a/src/bench/addrman.cpp b/src/bench/addrman.cpp deleted file mode 100644 index ceef6c29ab..0000000000 --- a/src/bench/addrman.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2020-2022 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 -#include -#include - -/* A "source" is a source address from which we have received a bunch of other addresses. */ - -static constexpr size_t NUM_SOURCES = 64; -static constexpr size_t NUM_ADDRESSES_PER_SOURCE = 256; - -static NetGroupManager EMPTY_NETGROUPMAN{std::vector()}; -static constexpr uint32_t ADDRMAN_CONSISTENCY_CHECK_RATIO{0}; - -static std::vector g_sources; -static std::vector> g_addresses; - -static void CreateAddresses() -{ - if (g_sources.size() > 0) { // already created - return; - } - - FastRandomContext rng(uint256(std::vector(32, 123))); - - auto randAddr = [&rng]() { - in6_addr addr; - memcpy(&addr, rng.randbytes(sizeof(addr)).data(), sizeof(addr)); - - uint16_t port; - memcpy(&port, rng.randbytes(sizeof(port)).data(), sizeof(port)); - if (port == 0) { - port = 1; - } - - CAddress ret(CService(addr, port), NODE_NETWORK); - - ret.nTime = Now(); - - return ret; - }; - - for (size_t source_i = 0; source_i < NUM_SOURCES; ++source_i) { - g_sources.emplace_back(randAddr()); - g_addresses.emplace_back(); - for (size_t addr_i = 0; addr_i < NUM_ADDRESSES_PER_SOURCE; ++addr_i) { - g_addresses[source_i].emplace_back(randAddr()); - } - } -} - -static void AddAddressesToAddrMan(AddrMan& addrman) -{ - for (size_t source_i = 0; source_i < NUM_SOURCES; ++source_i) { - addrman.Add(g_addresses[source_i], g_sources[source_i]); - } -} - -static void FillAddrMan(AddrMan& addrman) -{ - CreateAddresses(); - - AddAddressesToAddrMan(addrman); -} - -/* Benchmarks */ - -static void AddrManAdd(benchmark::Bench& bench) -{ - CreateAddresses(); - - bench.run([&] { - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - AddAddressesToAddrMan(addrman); - }); -} - -static void AddrManSelect(benchmark::Bench& bench) -{ - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - - FillAddrMan(addrman); - - bench.run([&] { - const auto& address = addrman.Select(); - assert(address.first.GetPort() > 0); - }); -} - -// The worst case performance of the Select() function is when there is only -// one address on the table, because it linearly searches every position of -// several buckets before identifying the correct bucket -static void AddrManSelectFromAlmostEmpty(benchmark::Bench& bench) -{ - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - - // Add one address to the new table - CService addr = Lookup("250.3.1.1", 8333, false).value(); - addrman.Add({CAddress(addr, NODE_NONE)}, addr); - - bench.run([&] { - (void)addrman.Select(); - }); -} - -static void AddrManSelectByNetwork(benchmark::Bench& bench) -{ - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - - // add single I2P address to new table - CService i2p_service; - i2p_service.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p"); - CAddress i2p_address(i2p_service, NODE_NONE); - i2p_address.nTime = Now(); - const CNetAddr source{LookupHost("252.2.2.2", false).value()}; - addrman.Add({i2p_address}, source); - - FillAddrMan(addrman); - - bench.run([&] { - (void)addrman.Select(/*new_only=*/false, {NET_I2P}); - }); -} - -static void AddrManGetAddr(benchmark::Bench& bench) -{ - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - - FillAddrMan(addrman); - - bench.run([&] { - const auto& addresses = addrman.GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt); - assert(addresses.size() > 0); - }); -} - -static void AddrManAddThenGood(benchmark::Bench& bench) -{ - auto markSomeAsGood = [](AddrMan& addrman) { - for (size_t source_i = 0; source_i < NUM_SOURCES; ++source_i) { - for (size_t addr_i = 0; addr_i < NUM_ADDRESSES_PER_SOURCE; ++addr_i) { - addrman.Good(g_addresses[source_i][addr_i]); - } - } - }; - - CreateAddresses(); - - bench.run([&] { - // To make the benchmark independent of the number of evaluations, we always prepare a new addrman. - // This is necessary because AddrMan::Good() method modifies the object, affecting the timing of subsequent calls - // to the same method and we want to do the same amount of work in every loop iteration. - // - // This has some overhead (exactly the result of AddrManAdd benchmark), but that overhead is constant so improvements in - // AddrMan::Good() will still be noticeable. - AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO}; - AddAddressesToAddrMan(addrman); - - markSomeAsGood(addrman); - }); -} - -BENCHMARK(AddrManAdd, benchmark::PriorityLevel::HIGH); -BENCHMARK(AddrManSelect, benchmark::PriorityLevel::HIGH); -BENCHMARK(AddrManSelectFromAlmostEmpty, benchmark::PriorityLevel::HIGH); -BENCHMARK(AddrManSelectByNetwork, benchmark::PriorityLevel::HIGH); -BENCHMARK(AddrManGetAddr, benchmark::PriorityLevel::HIGH); -BENCHMARK(AddrManAddThenGood, benchmark::PriorityLevel::HIGH); diff --git a/src/bench/base58.cpp b/src/bench/base58.cpp deleted file mode 100644 index f078c33964..0000000000 --- a/src/bench/base58.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2016-2022 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 - - -static void Base58Encode(benchmark::Bench& bench) -{ - static const std::array buff = { - { - 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, - 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, - 200, 24 - } - }; - bench.batch(buff.size()).unit("byte").run([&] { - EncodeBase58(buff); - }); -} - - -static void Base58CheckEncode(benchmark::Bench& bench) -{ - static const std::array buff = { - { - 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, - 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, - 200, 24 - } - }; - bench.batch(buff.size()).unit("byte").run([&] { - EncodeBase58Check(buff); - }); -} - - -static void Base58Decode(benchmark::Bench& bench) -{ - const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem"; - std::vector vch; - bench.batch(strlen(addr)).unit("byte").run([&] { - (void) DecodeBase58(addr, vch, 64); - }); -} - - -BENCHMARK(Base58Encode, benchmark::PriorityLevel::HIGH); -BENCHMARK(Base58CheckEncode, benchmark::PriorityLevel::HIGH); -BENCHMARK(Base58Decode, benchmark::PriorityLevel::HIGH); diff --git a/src/bench/bech32.cpp b/src/bench/bech32.cpp deleted file mode 100644 index 6aa73bd056..0000000000 --- a/src/bench/bech32.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2018-2022 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 - -using namespace util::hex_literals; - -static void Bech32Encode(benchmark::Bench& bench) -{ - constexpr std::array v{"c97f5a67ec381b760aeaf67573bc164845ff39a3bb26a1cee401ac67243b48db"_hex_u8}; - std::vector tmp = {0}; - tmp.reserve(1 + v.size() * 8 / 5); - ConvertBits<8, 5, true>([&](unsigned char c) { tmp.push_back(c); }, v.begin(), v.end()); - bench.batch(v.size()).unit("byte").run([&] { - bech32::Encode(bech32::Encoding::BECH32, "bc", tmp); - }); -} - - -static void Bech32Decode(benchmark::Bench& bench) -{ - std::string addr = "bc1qkallence7tjawwvy0dwt4twc62qjgaw8f4vlhyd006d99f09"; - bench.batch(addr.size()).unit("byte").run([&] { - bech32::Decode(addr); - }); -} - - -BENCHMARK(Bech32Encode, benchmark::PriorityLevel::HIGH); -BENCHMARK(Bech32Decode, benchmark::PriorityLevel::HIGH); diff --git a/src/bench/descriptors.cpp b/src/bench/descriptors.cpp deleted file mode 100644 index c45456645b..0000000000 --- a/src/bench/descriptors.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2019-2022 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