bench: Move constructors out of mempool_eviction hot loop

This commit is contained in:
MarcoFalke 2018-04-17 19:15:46 -04:00
parent 6b46288a08
commit 962d223e5c
1 changed files with 19 additions and 11 deletions

View File

@ -9,16 +9,16 @@
#include <list> #include <list>
#include <vector> #include <vector>
static void AddTx(const CMutableTransaction& tx, const CAmount& nFee, CTxMemPool& pool) static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool)
{ {
int64_t nTime = 0; int64_t nTime = 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.GetHash(), CTxMemPoolEntry( pool.addUnchecked(tx->GetHash(), CTxMemPoolEntry(
MakeTransactionRef(tx), nFee, nTime, nHeight, tx, nFee, nTime, nHeight,
spendsCoinbase, sigOpCost, lp)); spendsCoinbase, 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
@ -97,15 +97,23 @@ static void MempoolEviction(benchmark::State& state)
tx7.vout[1].nValue = 10 * COIN; tx7.vout[1].nValue = 10 * COIN;
CTxMemPool pool; CTxMemPool pool;
// Create transaction references outside the "hot loop"
const CTransactionRef tx1_r{MakeTransactionRef(tx1)};
const CTransactionRef tx2_r{MakeTransactionRef(tx2)};
const CTransactionRef tx3_r{MakeTransactionRef(tx3)};
const CTransactionRef tx4_r{MakeTransactionRef(tx4)};
const CTransactionRef tx5_r{MakeTransactionRef(tx5)};
const CTransactionRef tx6_r{MakeTransactionRef(tx6)};
const CTransactionRef tx7_r{MakeTransactionRef(tx7)};
while (state.KeepRunning()) { while (state.KeepRunning()) {
AddTx(tx1, 10000LL, pool); AddTx(tx1_r, 10000LL, pool);
AddTx(tx2, 5000LL, pool); AddTx(tx2_r, 5000LL, pool);
AddTx(tx3, 20000LL, pool); AddTx(tx3_r, 20000LL, pool);
AddTx(tx4, 7000LL, pool); AddTx(tx4_r, 7000LL, pool);
AddTx(tx5, 1000LL, pool); AddTx(tx5_r, 1000LL, pool);
AddTx(tx6, 1100LL, pool); AddTx(tx6_r, 1100LL, pool);
AddTx(tx7, 9000LL, pool); AddTx(tx7_r, 9000LL, pool);
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
pool.TrimToSize(GetVirtualTransactionSize(tx1)); pool.TrimToSize(GetVirtualTransactionSize(tx1));
} }