forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baaf390
commit d595e74
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 <net.h> | ||
#include <node/txreconciliation.h> | ||
|
||
|
||
/* Benchmarks */ | ||
|
||
static void ShouldFanoutTo(benchmark::Bench& bench) | ||
{ | ||
TxReconciliationTracker tracker(1); | ||
// Register 120 inbound peers | ||
int num_peers{120}; | ||
for(NodeId peer=0; peer < num_peers; peer++) { | ||
tracker.PreRegisterPeer(peer); | ||
tracker.RegisterPeer(peer, /*is_peer_inbound=*/true, 1, 1); | ||
} | ||
FastRandomContext rc{/*fDeterministic=*/true}; | ||
CSipHasher hasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL); | ||
|
||
// The target function uses caching, so we want to mimic tx repetitions | ||
// of the real-world behavior. | ||
std::vector<Wtxid> txs; | ||
for (size_t i = 0; i < 1000; i++) { | ||
txs.push_back(Wtxid::FromUint256(rc.rand256())); | ||
} | ||
|
||
bench.run([&] { | ||
size_t rand_i = rand() % txs.size(); | ||
for (NodeId peer = 0; peer < num_peers; ++peer) { | ||
tracker.ShouldFanoutTo(txs[rand_i], CSipHasher(hasher), peer,/*inbounds_nonrcncl_tx_relay=*/0, /*outbounds_nonrcncl_tx_relay=*/0); | ||
} | ||
}); | ||
} | ||
|
||
BENCHMARK(ShouldFanoutTo, benchmark::PriorityLevel::HIGH); |