Skip to content

Commit 059c8e6

Browse files
committed
bench: Add OrphanTxPool benchmark
1 parent 206f514 commit 059c8e6

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bench_bench_bitcoin_SOURCES = \
3333
bench/merkle_root.cpp \
3434
bench/mempool_eviction.cpp \
3535
bench/mempool_stress.cpp \
36+
bench/orphan_tx_pool.cpp \
3637
bench/rpc_blockchain.cpp \
3738
bench/rpc_mempool.cpp \
3839
bench/util_time.cpp \

src/bench/orphan_tx_pool.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/bench.h>
6+
7+
#include <amount.h>
8+
#include <net.h>
9+
#include <net_processing.h>
10+
#include <primitives/transaction.h>
11+
#include <random.h>
12+
#include <script/script.h>
13+
#include <sync.h>
14+
15+
#include <vector>
16+
17+
static constexpr CAmount CENT{1000000};
18+
extern bool AddOrphanTx(const CTransactionRef& tx, NodeId peer);
19+
extern unsigned int EvictOrphanTxs(unsigned int nMaxOrphans);
20+
21+
static void OrphanTxPool(benchmark::State& state)
22+
{
23+
FastRandomContext rand;
24+
std::vector<CTransactionRef> txs;
25+
for (unsigned int i = 0; i < DEFAULT_MAX_ORPHAN_TRANSACTIONS; ++i) {
26+
CMutableTransaction tx;
27+
tx.vin.resize(1);
28+
tx.vin[0].prevout.n = 0;
29+
tx.vin[0].prevout.hash = rand.rand256();
30+
tx.vin[0].scriptSig << OP_1;
31+
tx.vout.resize(1);
32+
tx.vout[0].nValue = 1 * CENT;
33+
tx.vout[0].scriptPubKey << OP_1;
34+
txs.emplace_back(MakeTransactionRef(tx));
35+
}
36+
37+
LOCK(g_cs_orphans);
38+
while (state.KeepRunning()) {
39+
for (const auto& tx : txs) {
40+
AddOrphanTx(tx, 0);
41+
}
42+
EvictOrphanTxs(0);
43+
}
44+
}
45+
46+
BENCHMARK(OrphanTxPool, 10000);

0 commit comments

Comments
 (0)