mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Benchmark BnB in the worst case where it exhausts
This commit is contained in:
parent
6a34ff5335
commit
76d2f068a4
@ -4,6 +4,7 @@
|
||||
|
||||
#include <bench/bench.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/coinselection.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
@ -61,4 +62,47 @@ static void CoinSelection(benchmark::State& state)
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::set<CInputCoin> CoinSet;
|
||||
|
||||
// Copied from src/wallet/test/coinselector_tests.cpp
|
||||
static void add_coin(const CAmount& nValue, int nInput, std::vector<CInputCoin>& set)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
tx.vout.resize(nInput + 1);
|
||||
tx.vout[nInput].nValue = nValue;
|
||||
set.emplace_back(MakeTransactionRef(tx), nInput);
|
||||
}
|
||||
// Copied from src/wallet/test/coinselector_tests.cpp
|
||||
static CAmount make_hard_case(int utxos, std::vector<CInputCoin>& utxo_pool)
|
||||
{
|
||||
utxo_pool.clear();
|
||||
CAmount target = 0;
|
||||
for (int i = 0; i < utxos; ++i) {
|
||||
target += (CAmount)1 << (utxos+i);
|
||||
add_coin((CAmount)1 << (utxos+i), 2*i, utxo_pool);
|
||||
add_coin(((CAmount)1 << (utxos+i)) + ((CAmount)1 << (utxos-1-i)), 2*i + 1, utxo_pool);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
static void BnBExhaustion(benchmark::State& state)
|
||||
{
|
||||
// Setup
|
||||
std::vector<CInputCoin> utxo_pool;
|
||||
CoinSet selection;
|
||||
CAmount value_ret = 0;
|
||||
CAmount not_input_fees = 0;
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
// Benchmark
|
||||
CAmount target = make_hard_case(17, utxo_pool);
|
||||
SelectCoinsBnB(utxo_pool, target, 0, selection, value_ret, not_input_fees); // Should exhaust
|
||||
|
||||
// Cleanup
|
||||
utxo_pool.clear();
|
||||
selection.clear();
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(CoinSelection, 650);
|
||||
BENCHMARK(BnBExhaustion, 650);
|
||||
|
Loading…
Reference in New Issue
Block a user