aboutsummaryrefslogtreecommitdiff
path: root/src/bench/coin_selection.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-03-06 14:24:15 -0500
committerAndrew Chow <achow101-github@achow101.com>2018-03-13 12:39:35 -0400
commit76d2f068a4cbd2bfe50c166fe0babfc5f17acaf4 (patch)
tree0d98fbdba561f701632b872162c171fdbe32b1f2 /src/bench/coin_selection.cpp
parent6a34ff5335786615771ca423134a484b04831c4e (diff)
downloadbitcoin-76d2f068a4cbd2bfe50c166fe0babfc5f17acaf4.tar.xz
Benchmark BnB in the worst case where it exhausts
Diffstat (limited to 'src/bench/coin_selection.cpp')
-rw-r--r--src/bench/coin_selection.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp
index 605d9e3e66..4b2a0e72fe 100644
--- a/src/bench/coin_selection.cpp
+++ b/src/bench/coin_selection.cpp
@@ -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);