Changeset View
Changeset View
Standalone View
Standalone View
src/bench/mempool_eviction.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <list> | #include <list> | ||||
#include <vector> | #include <vector> | ||||
static void AddTx(const CTransaction &tx, const Amount &nFee, | static void AddTx(const CTransactionRef &tx, const Amount &nFee, | ||||
CTxMemPool &pool) { | CTxMemPool &pool) { | ||||
int64_t nTime = 0; | int64_t nTime = 0; | ||||
double dPriority = 10.0; | double dPriority = 10.0; | ||||
unsigned int nHeight = 1; | unsigned int nHeight = 1; | ||||
bool spendsCoinbase = false; | bool spendsCoinbase = false; | ||||
unsigned int sigOpCost = 4; | unsigned int sigOpCost = 4; | ||||
LockPoints lp; | LockPoints lp; | ||||
pool.addUnchecked(tx.GetId(), | pool.addUnchecked(tx->GetId(), | ||||
CTxMemPoolEntry(MakeTransactionRef(tx), nFee, nTime, | CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight, | ||||
dPriority, nHeight, tx.GetValueOut(), | tx->GetValueOut(), spendsCoinbase, | ||||
spendsCoinbase, sigOpCost, lp)); | sigOpCost, lp)); | ||||
} | } | ||||
// Right now this is only testing eviction performance in an extremely small | // Right now this is only testing eviction performance in an extremely small | ||||
// mempool. Code needs to be written to generate a much wider variety of | // mempool. Code needs to be written to generate a much wider variety of | ||||
// unique transactions for a more meaningful performance measurement. | // unique transactions for a more meaningful performance measurement. | ||||
static void MempoolEviction(benchmark::State &state) { | static void MempoolEviction(benchmark::State &state) { | ||||
CMutableTransaction tx1 = CMutableTransaction(); | CMutableTransaction tx1 = CMutableTransaction(); | ||||
tx1.vin.resize(1); | tx1.vin.resize(1); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | static void MempoolEviction(benchmark::State &state) { | ||||
tx7.vout.resize(2); | tx7.vout.resize(2); | ||||
tx7.vout[0].scriptPubKey = CScript() << OP_7 << OP_EQUAL; | tx7.vout[0].scriptPubKey = CScript() << OP_7 << OP_EQUAL; | ||||
tx7.vout[0].nValue = 10 * COIN; | tx7.vout[0].nValue = 10 * COIN; | ||||
tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL; | tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL; | ||||
tx7.vout[1].nValue = 10 * COIN; | tx7.vout[1].nValue = 10 * COIN; | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
CTransaction t1(tx1); | // Create transaction references outside the "hot loop" | ||||
CTransaction t2(tx2); | const CTransactionRef tx1_r{MakeTransactionRef(tx1)}; | ||||
CTransaction t3(tx3); | const CTransactionRef tx2_r{MakeTransactionRef(tx2)}; | ||||
CTransaction t4(tx4); | const CTransactionRef tx3_r{MakeTransactionRef(tx3)}; | ||||
CTransaction t5(tx5); | const CTransactionRef tx4_r{MakeTransactionRef(tx4)}; | ||||
CTransaction t6(tx6); | const CTransactionRef tx5_r{MakeTransactionRef(tx5)}; | ||||
CTransaction t7(tx1); | const CTransactionRef tx6_r{MakeTransactionRef(tx6)}; | ||||
const CTransactionRef tx7_r{MakeTransactionRef(tx7)}; | |||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
AddTx(t1, 10000 * SATOSHI, pool); | AddTx(tx1_r, 10000 * SATOSHI, pool); | ||||
AddTx(t2, 5000 * SATOSHI, pool); | AddTx(tx2_r, 5000 * SATOSHI, pool); | ||||
AddTx(t3, 20000 * SATOSHI, pool); | AddTx(tx3_r, 20000 * SATOSHI, pool); | ||||
AddTx(t4, 7000 * SATOSHI, pool); | AddTx(tx4_r, 7000 * SATOSHI, pool); | ||||
AddTx(t5, 1000 * SATOSHI, pool); | AddTx(tx5_r, 1000 * SATOSHI, pool); | ||||
AddTx(t6, 1100 * SATOSHI, pool); | AddTx(tx6_r, 1100 * SATOSHI, pool); | ||||
AddTx(t7, 9000 * SATOSHI, pool); | AddTx(tx7_r, 9000 * SATOSHI, pool); | ||||
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); | pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); | ||||
pool.TrimToSize(t1.GetTotalSize()); | pool.TrimToSize(GetVirtualTransactionSize(*tx1_r)); | ||||
} | } | ||||
} | } | ||||
BENCHMARK(MempoolEviction, 41000); | BENCHMARK(MempoolEviction, 41000); |