mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
Merge 8b19137a68
into 66aa6a47bd
This commit is contained in:
commit
bc9326d2b5
11 changed files with 35 additions and 654 deletions
|
@ -22,18 +22,18 @@ After compiling bitcoin-core, the benchmarks can be run with:
|
|||
|
||||
The output will look similar to:
|
||||
```
|
||||
| ns/op | op/s | err% | total | benchmark
|
||||
|--------------------:|--------------------:|--------:|----------:|:----------
|
||||
| 57,927,463.00 | 17.26 | 3.6% | 0.66 | `AddrManAdd`
|
||||
| 677,816.00 | 1,475.33 | 4.9% | 0.01 | `AddrManGetAddr`
|
||||
|
||||
...
|
||||
|
||||
| ns/byte | byte/s | err% | total | benchmark
|
||||
|--------------------:|--------------------:|--------:|----------:|:----------
|
||||
| 127.32 | 7,854,302.69 | 0.3% | 0.00 | `Base58CheckEncode`
|
||||
| 31.95 | 31,303,226.99 | 0.2% | 0.00 | `Base58Decode`
|
||||
|
||||
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|
||||
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|
||||
| 720,914.00 | 1,387.13 | 1.4% | 7,412,886.58 | 3,161,517.17 | 2.345 | 1,021,129.90 | 1.0% | 0.20 | `AddAndRemoveDisconnectedBlockTransactions10`
|
||||
| 611,867.00 | 1,634.34 | 0.5% | 7,649,982.92 | 2,670,775.17 | 2.864 | 1,056,808.83 | 0.4% | 0.07 | `AddAndRemoveDisconnectedBlockTransactions90`
|
||||
| 619,097.20 | 1,615.26 | 1.0% | 7,668,842.50 | 2,668,561.30 | 2.874 | 1,059,370.50 | 0.3% | 0.07 | `AddAndRemoveDisconnectedBlockTransactionsAll`
|
||||
| 159,134.17 | 6,284.01 | 1.3% | 2,071,425.00 | 694,174.43 | 2.984 | 267,128.50 | 0.4% | 0.01 | `AssembleBlock`
|
||||
...
|
||||
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|
||||
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|
||||
| 7,188.44 | 139,112.17 | 2.0% | 86,159.12 | 29,225.32 | 2.948 | 8,224.78 | 1.3% | 0.01 | `Linearize16TxWorstCase120Iters`
|
||||
| 2,030.32 | 492,532.65 | 1.1% | 22,864.15 | 8,028.46 | 2.848 | 2,367.65 | 0.9% | 0.01 | `Linearize16TxWorstCase20Iters`
|
||||
...
|
||||
```
|
||||
|
||||
|
@ -47,12 +47,30 @@ or using a regex filter to only run certain benchmarks.
|
|||
|
||||
Notes
|
||||
---------------------
|
||||
More benchmarks are needed for, in no particular order:
|
||||
- Script Validation
|
||||
- Coins database
|
||||
- Memory pool
|
||||
- Cuckoo Cache
|
||||
- P2P throughput
|
||||
|
||||
Benchmarks help with monitoring for performance regressions and act as a scope
|
||||
for future performance improvements. They should cover components that impact
|
||||
performance critical functions of the system. Functions are performance
|
||||
critical, if their performance impacts users and the cost associated with a
|
||||
degradation in performance is high. A non-exhaustive list:
|
||||
|
||||
- Initial block download (Cost: slow IBD results in full node operation being
|
||||
less accessible)
|
||||
- Block template creation (Cost: slow block template creation may result in
|
||||
lower fee revenue for miners)
|
||||
- Block propagation (Cost: slow block propagation may increase the rate of
|
||||
orphaned blocks)
|
||||
|
||||
Benchmark additions and performance improvements are valuable if they target
|
||||
the user facing functions mentioned above. If a clear end-to-end performance
|
||||
improvement cannot be demonstrated, the pull request is likely to be rejected.
|
||||
The change might also be rejected if the code bloat or review/maintenance is
|
||||
too much to justify the improvement.
|
||||
|
||||
Benchmarks are ill-suited for testing of denial of service issues as they are
|
||||
restricted to the same input set (introducing bias). [Fuzz
|
||||
tests](/doc/fuzzing.md) are better suited for this purpose, as they are much
|
||||
better (and aimed) at exploring the possible input space.
|
||||
|
||||
Going Further
|
||||
--------------------
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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 <addrman.h>
|
||||
#include <bench/bench.h>
|
||||
#include <compat/compat.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <netgroup.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
#include <span.h>
|
||||
#include <uint256.h>
|
||||
#include <util/check.h>
|
||||
#include <util/time.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
/* 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<bool>()};
|
||||
static constexpr uint32_t ADDRMAN_CONSISTENCY_CHECK_RATIO{0};
|
||||
|
||||
static std::vector<CAddress> g_sources;
|
||||
static std::vector<std::vector<CAddress>> g_addresses;
|
||||
|
||||
static void CreateAddresses()
|
||||
{
|
||||
if (g_sources.size() > 0) { // already created
|
||||
return;
|
||||
}
|
||||
|
||||
FastRandomContext rng(uint256(std::vector<unsigned char>(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<NodeSeconds>();
|
||||
|
||||
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<NodeSeconds>();
|
||||
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);
|
|
@ -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 <base58.h>
|
||||
#include <bench/bench.h>
|
||||
#include <span.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
|
||||
static void Base58Encode(benchmark::Bench& bench)
|
||||
{
|
||||
static const std::array<unsigned char, 32> 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<unsigned char, 32> 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<unsigned char> 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);
|
|
@ -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 <bech32.h>
|
||||
#include <bench/bench.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace util::hex_literals;
|
||||
|
||||
static void Bech32Encode(benchmark::Bench& bench)
|
||||
{
|
||||
constexpr std::array<uint8_t, 32> v{"c97f5a67ec381b760aeaf67573bc164845ff39a3bb26a1cee401ac67243b48db"_hex_u8};
|
||||
std::vector<unsigned char> 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);
|
|
@ -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 <bench/bench.h>
|
||||
#include <key.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <script/script.h>
|
||||
#include <script/signingprovider.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
static void ExpandDescriptor(benchmark::Bench& bench)
|
||||
{
|
||||
ECC_Context ecc_context{};
|
||||
|
||||
const auto desc_str = "sh(wsh(multi(16,03669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0,0260b2003c386519fc9eadf2b5cf124dd8eea4c4e68d5e154050a9346ea98ce600,0362a74e399c39ed5593852a30147f2959b56bb827dfa3e60e464b02ccf87dc5e8,0261345b53de74a4d721ef877c255429961b7e43714171ac06168d7e08c542a8b8,02da72e8b46901a65d4374fe6315538d8f368557dda3a1dcf9ea903f3afe7314c8,0318c82dd0b53fd3a932d16e0ba9e278fcc937c582d5781be626ff16e201f72286,0297ccef1ef99f9d73dec9ad37476ddb232f1238aff877af19e72ba04493361009,02e502cfd5c3f972fe9a3e2a18827820638f96b6f347e54d63deb839011fd5765d,03e687710f0e3ebe81c1037074da939d409c0025f17eb86adb9427d28f0f7ae0e9,02c04d3a5274952acdbc76987f3184b346a483d43be40874624b29e3692c1df5af,02ed06e0f418b5b43a7ec01d1d7d27290fa15f75771cb69b642a51471c29c84acd,036d46073cbb9ffee90473f3da429abc8de7f8751199da44485682a989a4bebb24,02f5d1ff7c9029a80a4e36b9a5497027ef7f3e73384a4a94fbfe7c4e9164eec8bc,02e41deffd1b7cce11cde209a781adcffdabd1b91c0ba0375857a2bfd9302419f3,02d76625f7956a7fc505ab02556c23ee72d832f1bac391bcd2d3abce5710a13d06,0399eb0a5487515802dc14544cf10b3666623762fbed2ec38a3975716e2c29c232)))";
|
||||
const std::pair<int64_t, int64_t> range = {0, 1000};
|
||||
FlatSigningProvider provider;
|
||||
std::string error;
|
||||
auto descs = Parse(desc_str, provider, error);
|
||||
|
||||
bench.run([&] {
|
||||
for (int i = range.first; i <= range.second; ++i) {
|
||||
std::vector<CScript> scripts;
|
||||
bool success = descs[0]->Expand(i, provider, scripts, provider);
|
||||
assert(success);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(ExpandDescriptor, benchmark::PriorityLevel::HIGH);
|
|
@ -1,64 +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 <bench/bench.h>
|
||||
#include <logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
// All but 2 of the benchmarks should have roughly similar performance:
|
||||
//
|
||||
// LogWithoutDebug should be ~3 orders of magnitude faster, as nothing is logged.
|
||||
//
|
||||
// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.
|
||||
|
||||
static void Logging(benchmark::Bench& bench, const std::vector<const char*>& extra_args, const std::function<void()>& log)
|
||||
{
|
||||
// Reset any enabled logging categories from a previous benchmark run.
|
||||
LogInstance().DisableCategory(BCLog::LogFlags::ALL);
|
||||
|
||||
TestingSetup test_setup{
|
||||
ChainType::REGTEST,
|
||||
{.extra_args = extra_args},
|
||||
};
|
||||
|
||||
bench.run([&] { log(); });
|
||||
}
|
||||
|
||||
static void LogWithDebug(benchmark::Bench& bench)
|
||||
{
|
||||
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
|
||||
}
|
||||
|
||||
static void LogWithoutDebug(benchmark::Bench& bench)
|
||||
{
|
||||
Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
|
||||
}
|
||||
|
||||
static void LogWithThreadNames(benchmark::Bench& bench)
|
||||
{
|
||||
Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); });
|
||||
}
|
||||
|
||||
static void LogWithoutThreadNames(benchmark::Bench& bench)
|
||||
{
|
||||
Logging(bench, {"-logthreadnames=0"}, [] { LogInfo("%s\n", "test"); });
|
||||
}
|
||||
|
||||
static void LogWithoutWriteToFile(benchmark::Bench& bench)
|
||||
{
|
||||
// Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.
|
||||
Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
|
||||
LogInfo("%s\n", "test");
|
||||
LogDebug(BCLog::NET, "%s\n", "test");
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(LogWithDebug, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(LogWithoutDebug, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(LogWithThreadNames, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(LogWithoutThreadNames, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(LogWithoutWriteToFile, benchmark::PriorityLevel::HIGH);
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2024- 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 <bench/bench.h>
|
||||
#include <random.h>
|
||||
#include <stddef.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
std::string generateHexString(size_t length) {
|
||||
const auto hex_digits = "0123456789ABCDEF";
|
||||
FastRandomContext rng(/*fDeterministic=*/true);
|
||||
|
||||
std::string data;
|
||||
while (data.size() < length) {
|
||||
auto digit = hex_digits[rng.randbits(4)];
|
||||
data.push_back(digit);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static void HexParse(benchmark::Bench& bench)
|
||||
{
|
||||
auto data = generateHexString(130); // Generates 678B0EDA0A1FD30904D5A65E3568DB82DB2D918B0AD8DEA18A63FECCB877D07CAD1495C7157584D877420EF38B8DA473A6348B4F51811AC13C786B962BEE5668F9 by default
|
||||
|
||||
bench.batch(data.size()).unit("base16").run([&] {
|
||||
auto result = TryParseHex(data);
|
||||
assert(result != std::nullopt); // make sure we're measuring the successful case
|
||||
ankerl::nanobench::doNotOptimizeAway(result);
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(HexParse, benchmark::PriorityLevel::HIGH);
|
|
@ -1,154 +0,0 @@
|
|||
// Copyright (c) 2021-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 <bench/bench.h>
|
||||
#include <netaddress.h>
|
||||
#include <node/eviction.h>
|
||||
#include <random.h>
|
||||
#include <test/util/net.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
static void EvictionProtectionCommon(
|
||||
benchmark::Bench& bench,
|
||||
int num_candidates,
|
||||
std::function<void(NodeEvictionCandidate&)> candidate_setup_fn)
|
||||
{
|
||||
using Candidates = std::vector<NodeEvictionCandidate>;
|
||||
FastRandomContext random_context{true};
|
||||
|
||||
Candidates candidates{GetRandomNodeEvictionCandidates(num_candidates, random_context)};
|
||||
for (auto& c : candidates) {
|
||||
candidate_setup_fn(c);
|
||||
}
|
||||
|
||||
|
||||
bench.run([&] {
|
||||
// creating a copy has an overhead of about 3%, so it does not influence the benchmark results much.
|
||||
auto copy = candidates;
|
||||
ProtectEvictionCandidatesByRatio(copy);
|
||||
});
|
||||
}
|
||||
|
||||
/* Benchmarks */
|
||||
|
||||
static void EvictionProtection0Networks250Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/250,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_network = NET_IPV4;
|
||||
});
|
||||
}
|
||||
|
||||
static void EvictionProtection1Networks250Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/250,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_is_local = false;
|
||||
if (c.id >= 130 && c.id < 240) { // 110 Tor
|
||||
c.m_network = NET_ONION;
|
||||
} else {
|
||||
c.m_network = NET_IPV4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void EvictionProtection2Networks250Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/250,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_is_local = false;
|
||||
if (c.id >= 90 && c.id < 160) { // 70 Tor
|
||||
c.m_network = NET_ONION;
|
||||
} else if (c.id >= 170 && c.id < 250) { // 80 I2P
|
||||
c.m_network = NET_I2P;
|
||||
} else {
|
||||
c.m_network = NET_IPV4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void EvictionProtection3Networks050Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/50,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_is_local = (c.id == 28 || c.id == 47); // 2 localhost
|
||||
if (c.id >= 30 && c.id < 47) { // 17 I2P
|
||||
c.m_network = NET_I2P;
|
||||
} else if (c.id >= 24 && c.id < 28) { // 4 Tor
|
||||
c.m_network = NET_ONION;
|
||||
} else {
|
||||
c.m_network = NET_IPV4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void EvictionProtection3Networks100Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/100,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_is_local = (c.id >= 55 && c.id < 60); // 5 localhost
|
||||
if (c.id >= 70 && c.id < 80) { // 10 I2P
|
||||
c.m_network = NET_I2P;
|
||||
} else if (c.id >= 80 && c.id < 96) { // 16 Tor
|
||||
c.m_network = NET_ONION;
|
||||
} else {
|
||||
c.m_network = NET_IPV4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void EvictionProtection3Networks250Candidates(benchmark::Bench& bench)
|
||||
{
|
||||
EvictionProtectionCommon(
|
||||
bench,
|
||||
/*num_candidates=*/250,
|
||||
[](NodeEvictionCandidate& c) {
|
||||
c.m_connected = std::chrono::seconds{c.id};
|
||||
c.m_is_local = (c.id >= 140 && c.id < 160); // 20 localhost
|
||||
if (c.id >= 170 && c.id < 180) { // 10 I2P
|
||||
c.m_network = NET_I2P;
|
||||
} else if (c.id >= 190 && c.id < 240) { // 50 Tor
|
||||
c.m_network = NET_ONION;
|
||||
} else {
|
||||
c.m_network = NET_IPV4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Candidate numbers used for the benchmarks:
|
||||
// - 50 candidates simulates a possible use of -maxconnections
|
||||
// - 100 candidates approximates an average node with default settings
|
||||
// - 250 candidates is the number of peers reported by operators of busy nodes
|
||||
|
||||
// No disadvantaged networks, with 250 eviction candidates.
|
||||
BENCHMARK(EvictionProtection0Networks250Candidates, benchmark::PriorityLevel::HIGH);
|
||||
|
||||
// 1 disadvantaged network (Tor) with 250 eviction candidates.
|
||||
BENCHMARK(EvictionProtection1Networks250Candidates, benchmark::PriorityLevel::HIGH);
|
||||
|
||||
// 2 disadvantaged networks (I2P, Tor) with 250 eviction candidates.
|
||||
BENCHMARK(EvictionProtection2Networks250Candidates, benchmark::PriorityLevel::HIGH);
|
||||
|
||||
// 3 disadvantaged networks (I2P/localhost/Tor) with 50/100/250 eviction candidates.
|
||||
BENCHMARK(EvictionProtection3Networks050Candidates, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(EvictionProtection3Networks100Candidates, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(EvictionProtection3Networks250Candidates, benchmark::PriorityLevel::HIGH);
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright (c) 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 <bench/bench.h>
|
||||
#include <bench/data/block413567.raw.h>
|
||||
#include <span.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
static void HexStrBench(benchmark::Bench& bench)
|
||||
{
|
||||
auto const& data = benchmark::data::block413567;
|
||||
bench.batch(data.size()).unit("byte").run([&] {
|
||||
auto hex = HexStr(data);
|
||||
ankerl::nanobench::doNotOptimizeAway(hex);
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(HexStrBench, benchmark::PriorityLevel::HIGH);
|
|
@ -1,42 +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 <bench/bench.h>
|
||||
|
||||
#include <util/time.h>
|
||||
|
||||
static void BenchTimeDeprecated(benchmark::Bench& bench)
|
||||
{
|
||||
bench.run([&] {
|
||||
(void)GetTime();
|
||||
});
|
||||
}
|
||||
|
||||
static void BenchTimeMock(benchmark::Bench& bench)
|
||||
{
|
||||
SetMockTime(111);
|
||||
bench.run([&] {
|
||||
(void)GetTime<std::chrono::seconds>();
|
||||
});
|
||||
SetMockTime(0);
|
||||
}
|
||||
|
||||
static void BenchTimeMillis(benchmark::Bench& bench)
|
||||
{
|
||||
bench.run([&] {
|
||||
(void)GetTime<std::chrono::milliseconds>();
|
||||
});
|
||||
}
|
||||
|
||||
static void BenchTimeMillisSys(benchmark::Bench& bench)
|
||||
{
|
||||
bench.run([&] {
|
||||
(void)TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now());
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(BenchTimeDeprecated, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(BenchTimeMillis, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(BenchTimeMillisSys, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(BenchTimeMock, benchmark::PriorityLevel::HIGH);
|
Loading…
Reference in a new issue