Changeset View
Changeset View
Standalone View
Standalone View
src/bench/rpc_mempool.cpp
Show All 11 Lines | static void AddTx(const CTransactionRef &tx, const Amount &fee, | ||||
CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) { | CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) { | ||||
LockPoints lp; | LockPoints lp; | ||||
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0, | pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0, | ||||
/* height */ 1, | /* height */ 1, | ||||
/* spendsCoinbase */ false, | /* spendsCoinbase */ false, | ||||
/* sigOpCount */ 1, lp)); | /* sigOpCount */ 1, lp)); | ||||
} | } | ||||
static void RpcMempool(benchmark::State &state) { | static void RpcMempool(benchmark::Bench &bench) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK2(cs_main, pool.cs); | LOCK2(cs_main, pool.cs); | ||||
for (int i = 0; i < 1000; ++i) { | for (int i = 0; i < 1000; ++i) { | ||||
CMutableTransaction tx = CMutableTransaction(); | CMutableTransaction tx = CMutableTransaction(); | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << OP_1; | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; | tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; | ||||
tx.vout[0].nValue = i * COIN; | tx.vout[0].nValue = i * COIN; | ||||
const CTransactionRef tx_r{MakeTransactionRef(tx)}; | const CTransactionRef tx_r{MakeTransactionRef(tx)}; | ||||
AddTx(tx_r, /* fee */ i * COIN, pool); | AddTx(tx_r, /* fee */ i * COIN, pool); | ||||
} | } | ||||
while (state.KeepRunning()) { | bench.run([&] { (void)MempoolToJSON(pool, /*verbose*/ true); }); | ||||
(void)MempoolToJSON(pool, /*verbose*/ true); | |||||
} | |||||
} | } | ||||
BENCHMARK(RpcMempool, 40); | BENCHMARK(RpcMempool); |