Skip to content

Commit

Permalink
add bench for ShouldFanoutTo
Browse files Browse the repository at this point in the history
  • Loading branch information
mzumsande authored and naumenkogs committed Jan 9, 2024
1 parent baaf390 commit d595e74
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bench_bench_bitcoin_SOURCES = \
bench/rpc_mempool.cpp \
bench/streams_findbyte.cpp \
bench/strencodings.cpp \
bench/txreconciliation.cpp \
bench/util_time.cpp \
bench/verify_script.cpp \
bench/xor.cpp
Expand Down
40 changes: 40 additions & 0 deletions src/bench/txreconciliation.cpp
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);

0 comments on commit d595e74

Please sign in to comment.