1 // Copyright (c) 2011-2016 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.
6 #include "policy/policy.h"
12 static void AddTx(const CTransaction
& tx
, const CAmount
& nFee
, CTxMemPool
& pool
)
15 unsigned int nHeight
= 1;
16 bool spendsCoinbase
= false;
17 unsigned int sigOpCost
= 4;
19 pool
.addUnchecked(tx
.GetHash(), CTxMemPoolEntry(
20 MakeTransactionRef(tx
), nFee
, nTime
, nHeight
,
21 spendsCoinbase
, sigOpCost
, lp
));
24 // Right now this is only testing eviction performance in an extremely small
25 // mempool. Code needs to be written to generate a much wider variety of
26 // unique transactions for a more meaningful performance measurement.
27 static void MempoolEviction(benchmark::State
& state
)
29 CMutableTransaction tx1
= CMutableTransaction();
31 tx1
.vin
[0].scriptSig
= CScript() << OP_1
;
33 tx1
.vout
[0].scriptPubKey
= CScript() << OP_1
<< OP_EQUAL
;
34 tx1
.vout
[0].nValue
= 10 * COIN
;
36 CMutableTransaction tx2
= CMutableTransaction();
38 tx2
.vin
[0].scriptSig
= CScript() << OP_2
;
40 tx2
.vout
[0].scriptPubKey
= CScript() << OP_2
<< OP_EQUAL
;
41 tx2
.vout
[0].nValue
= 10 * COIN
;
43 CMutableTransaction tx3
= CMutableTransaction();
45 tx3
.vin
[0].prevout
= COutPoint(tx2
.GetHash(), 0);
46 tx3
.vin
[0].scriptSig
= CScript() << OP_2
;
48 tx3
.vout
[0].scriptPubKey
= CScript() << OP_3
<< OP_EQUAL
;
49 tx3
.vout
[0].nValue
= 10 * COIN
;
51 CMutableTransaction tx4
= CMutableTransaction();
53 tx4
.vin
[0].prevout
.SetNull();
54 tx4
.vin
[0].scriptSig
= CScript() << OP_4
;
55 tx4
.vin
[1].prevout
.SetNull();
56 tx4
.vin
[1].scriptSig
= CScript() << OP_4
;
58 tx4
.vout
[0].scriptPubKey
= CScript() << OP_4
<< OP_EQUAL
;
59 tx4
.vout
[0].nValue
= 10 * COIN
;
60 tx4
.vout
[1].scriptPubKey
= CScript() << OP_4
<< OP_EQUAL
;
61 tx4
.vout
[1].nValue
= 10 * COIN
;
63 CMutableTransaction tx5
= CMutableTransaction();
65 tx5
.vin
[0].prevout
= COutPoint(tx4
.GetHash(), 0);
66 tx5
.vin
[0].scriptSig
= CScript() << OP_4
;
67 tx5
.vin
[1].prevout
.SetNull();
68 tx5
.vin
[1].scriptSig
= CScript() << OP_5
;
70 tx5
.vout
[0].scriptPubKey
= CScript() << OP_5
<< OP_EQUAL
;
71 tx5
.vout
[0].nValue
= 10 * COIN
;
72 tx5
.vout
[1].scriptPubKey
= CScript() << OP_5
<< OP_EQUAL
;
73 tx5
.vout
[1].nValue
= 10 * COIN
;
75 CMutableTransaction tx6
= CMutableTransaction();
77 tx6
.vin
[0].prevout
= COutPoint(tx4
.GetHash(), 1);
78 tx6
.vin
[0].scriptSig
= CScript() << OP_4
;
79 tx6
.vin
[1].prevout
.SetNull();
80 tx6
.vin
[1].scriptSig
= CScript() << OP_6
;
82 tx6
.vout
[0].scriptPubKey
= CScript() << OP_6
<< OP_EQUAL
;
83 tx6
.vout
[0].nValue
= 10 * COIN
;
84 tx6
.vout
[1].scriptPubKey
= CScript() << OP_6
<< OP_EQUAL
;
85 tx6
.vout
[1].nValue
= 10 * COIN
;
87 CMutableTransaction tx7
= CMutableTransaction();
89 tx7
.vin
[0].prevout
= COutPoint(tx5
.GetHash(), 0);
90 tx7
.vin
[0].scriptSig
= CScript() << OP_5
;
91 tx7
.vin
[1].prevout
= COutPoint(tx6
.GetHash(), 0);
92 tx7
.vin
[1].scriptSig
= CScript() << OP_6
;
94 tx7
.vout
[0].scriptPubKey
= CScript() << OP_7
<< OP_EQUAL
;
95 tx7
.vout
[0].nValue
= 10 * COIN
;
96 tx7
.vout
[1].scriptPubKey
= CScript() << OP_7
<< OP_EQUAL
;
97 tx7
.vout
[1].nValue
= 10 * COIN
;
101 while (state
.KeepRunning()) {
102 AddTx(tx1
, 10000LL, pool
);
103 AddTx(tx2
, 5000LL, pool
);
104 AddTx(tx3
, 20000LL, pool
);
105 AddTx(tx4
, 7000LL, pool
);
106 AddTx(tx5
, 1000LL, pool
);
107 AddTx(tx6
, 1100LL, pool
);
108 AddTx(tx7
, 9000LL, pool
);
109 pool
.TrimToSize(pool
.DynamicMemoryUsage() * 3 / 4);
110 pool
.TrimToSize(GetVirtualTransactionSize(tx1
));
114 BENCHMARK(MempoolEviction
);