Skip to content

Commit fa38535

Browse files
author
MarcoFalke
committed
bench: Benchmark MempoolToJSON
1 parent fa5dc35 commit fa38535

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

build_msvc/bench_bitcoin/bench_bitcoin.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<ClCompile Include="..\..\src\bench\examples.cpp" />
3333
<ClCompile Include="..\..\src\bench\lockedpool.cpp" />
3434
<ClCompile Include="..\..\src\bench\mempool_eviction.cpp" />
35+
<ClCompile Include="..\..\src\bench\rpc_mempool.cpp" />
3536
<ClCompile Include="..\..\src\bench\merkle_root.cpp" />
3637
<ClCompile Include="..\..\src\bench\rollingbloom.cpp" />
3738
<ClCompile Include="..\..\src\bench\verify_script.cpp" />

src/Makefile.bench.include

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bench_bench_bitcoin_SOURCES = \
2626
bench/gcs_filter.cpp \
2727
bench/merkle_root.cpp \
2828
bench/mempool_eviction.cpp \
29+
bench/rpc_mempool.cpp \
2930
bench/verify_script.cpp \
3031
bench/base58.cpp \
3132
bench/bech32.cpp \
@@ -37,6 +38,7 @@ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
3738
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
3839
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
3940
bench_bench_bitcoin_LDADD = \
41+
$(LIBBITCOIN_SERVER) \
4042
$(LIBBITCOIN_WALLET) \
4143
$(LIBBITCOIN_SERVER) \
4244
$(LIBBITCOIN_COMMON) \
@@ -47,7 +49,9 @@ bench_bench_bitcoin_LDADD = \
4749
$(LIBLEVELDB_SSE42) \
4850
$(LIBMEMENV) \
4951
$(LIBSECP256K1) \
50-
$(LIBUNIVALUE)
52+
$(LIBUNIVALUE) \
53+
$(EVENT_PTHREADS_LIBS) \
54+
$(EVENT_LIBS)
5155

5256
if ENABLE_ZMQ
5357
bench_bench_bitcoin_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)

src/bench/rpc_mempool.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2011-2019 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+
#include <policy/policy.h>
7+
#include <rpc/blockchain.h>
8+
#include <txmempool.h>
9+
10+
#include <univalue.h>
11+
12+
#include <list>
13+
#include <vector>
14+
15+
static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
16+
{
17+
LockPoints lp;
18+
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0, /* height */ 1, /* spendsCoinbase */ false, /* sigOpCost */ 4, lp));
19+
}
20+
21+
static void RpcMempool(benchmark::State& state)
22+
{
23+
CTxMemPool pool;
24+
LOCK2(cs_main, pool.cs);
25+
26+
for (int i = 0; i < 1000; ++i) {
27+
CMutableTransaction tx = CMutableTransaction();
28+
tx.vin.resize(1);
29+
tx.vin[0].scriptSig = CScript() << OP_1;
30+
tx.vin[0].scriptWitness.stack.push_back({1});
31+
tx.vout.resize(1);
32+
tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
33+
tx.vout[0].nValue = i;
34+
const CTransactionRef tx_r{MakeTransactionRef(tx)};
35+
AddTx(tx_r, /* fee */ i, pool);
36+
}
37+
38+
while (state.KeepRunning()) {
39+
(void)MempoolToJSON(pool, /*verbose*/ true);
40+
}
41+
}
42+
43+
BENCHMARK(RpcMempool, 40);

0 commit comments

Comments
 (0)