Skip to content

Commit 9b91aae

Browse files
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 <[email protected]>
1 parent 22a4d14 commit 9b91aae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/bench/addrman.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <addrman.h>
66
#include <bench/bench.h>
7+
#include <netbase.h>
78
#include <netgroup.h>
89
#include <random.h>
910
#include <util/check.h>
@@ -71,6 +72,13 @@ static void FillAddrMan(AddrMan& addrman)
7172
AddAddressesToAddrMan(addrman);
7273
}
7374

75+
static CNetAddr ResolveIP(const std::string& ip)
76+
{
77+
CNetAddr addr;
78+
LookupHost(ip, addr, false);
79+
return addr;
80+
}
81+
7482
/* Benchmarks */
7583

7684
static void AddrManAdd(benchmark::Bench& bench)
@@ -95,6 +103,25 @@ static void AddrManSelect(benchmark::Bench& bench)
95103
});
96104
}
97105

106+
static void AddrManSelectByNetwork(benchmark::Bench& bench)
107+
{
108+
AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO};
109+
110+
// add single I2P address to new table
111+
CService i2p_service;
112+
i2p_service.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p");
113+
CAddress i2p_address(i2p_service, NODE_NONE);
114+
i2p_address.nTime = Now<NodeSeconds>();
115+
CNetAddr source = ResolveIP("252.2.2.2");
116+
addrman.Add({i2p_address}, source);
117+
118+
FillAddrMan(addrman);
119+
120+
bench.run([&] {
121+
(void)addrman.Select(/*new_only=*/false, NET_I2P);
122+
});
123+
}
124+
98125
static void AddrManGetAddr(benchmark::Bench& bench)
99126
{
100127
AddrMan addrman{EMPTY_NETGROUPMAN, /*deterministic=*/false, ADDRMAN_CONSISTENCY_CHECK_RATIO};
@@ -135,5 +162,6 @@ static void AddrManAddThenGood(benchmark::Bench& bench)
135162

136163
BENCHMARK(AddrManAdd, benchmark::PriorityLevel::HIGH);
137164
BENCHMARK(AddrManSelect, benchmark::PriorityLevel::HIGH);
165+
BENCHMARK(AddrManSelectByNetwork, benchmark::PriorityLevel::HIGH);
138166
BENCHMARK(AddrManGetAddr, benchmark::PriorityLevel::HIGH);
139167
BENCHMARK(AddrManAddThenGood, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)