aboutsummaryrefslogtreecommitdiff
path: root/src/bench/addrman.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2023-02-18 17:03:56 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2023-03-17 18:02:40 -0700
commit9b91aae08579c77d2fd5506804c8e2e0cda0d274 (patch)
treed5a1aa47d56a125e4c55ef57adef81ddd9d56988 /src/bench/addrman.cpp
parent22a4d1489c0678a90c00318203cfce61672f20b7 (diff)
downloadbitcoin-9b91aae08579c77d2fd5506804c8e2e0cda0d274.tar.xz
bench: add coverage for addrman select with network parameter
to evaluate the worst case performance with the network parameter passed through, fill the new table with addresses then add a singular I2P address to retrieve Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
Diffstat (limited to 'src/bench/addrman.cpp')
-rw-r--r--src/bench/addrman.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bench/addrman.cpp b/src/bench/addrman.cpp
index d6b52eb587..b8c69d0a63 100644
--- a/src/bench/addrman.cpp
+++ b/src/bench/addrman.cpp
@@ -4,6 +4,7 @@
#include <addrman.h>
#include <bench/bench.h>
+#include <netbase.h>
#include <netgroup.h>
#include <random.h>
#include <util/check.h>
@@ -71,6 +72,13 @@ static void FillAddrMan(AddrMan& addrman)
AddAddressesToAddrMan(addrman);
}
+static CNetAddr ResolveIP(const std::string& ip)
+{
+ CNetAddr addr;
+ LookupHost(ip, addr, false);
+ return addr;
+}
+
/* Benchmarks */
static void AddrManAdd(benchmark::Bench& bench)
@@ -95,6 +103,25 @@ static void AddrManSelect(benchmark::Bench& bench)
});
}
+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>();
+ CNetAddr source = ResolveIP("252.2.2.2");
+ 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};
@@ -135,5 +162,6 @@ static void AddrManAddThenGood(benchmark::Bench& bench)
BENCHMARK(AddrManAdd, benchmark::PriorityLevel::HIGH);
BENCHMARK(AddrManSelect, benchmark::PriorityLevel::HIGH);
+BENCHMARK(AddrManSelectByNetwork, benchmark::PriorityLevel::HIGH);
BENCHMARK(AddrManGetAddr, benchmark::PriorityLevel::HIGH);
BENCHMARK(AddrManAddThenGood, benchmark::PriorityLevel::HIGH);