Changeset View
Changeset View
Standalone View
Standalone View
src/bench/coin_selection.cpp
// Copyright (c) 2012-2016 The Bitcoin Core developers | // Copyright (c) 2012-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 <chainparams.h> | #include <chainparams.h> | ||||
#include <interfaces/chain.h> | |||||
#include <wallet/coinselection.h> | #include <wallet/coinselection.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <memory> | #include <memory> | ||||
#include <set> | #include <set> | ||||
static void addCoin(const Amount nValue, const CWallet &wallet, | static void addCoin(const Amount nValue, const CWallet &wallet, | ||||
std::vector<OutputGroup> &groups) { | std::vector<OutputGroup> &groups) { | ||||
Show All 17 Lines | |||||
// to build up more complicated scenarios in order to get meaningful | // to build up more complicated scenarios in order to get meaningful | ||||
// measurements of performance. From laanwj, "Wallet coin selection is probably | // measurements of performance. From laanwj, "Wallet coin selection is probably | ||||
// the hardest, as you need a wider selection of scenarios, just testing the | // the hardest, as you need a wider selection of scenarios, just testing the | ||||
// same one over and over isn't too useful. Generating random isn't useful | // same one over and over isn't too useful. Generating random isn't useful | ||||
// either for measurements." | // either for measurements." | ||||
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) | // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) | ||||
static void CoinSelection(benchmark::State &state) { | static void CoinSelection(benchmark::State &state) { | ||||
SelectParams(CBaseChainParams::REGTEST); | SelectParams(CBaseChainParams::REGTEST); | ||||
const CWallet wallet(Params(), WalletLocation(), | |||||
auto chain = interfaces::MakeChain(); | |||||
const CWallet wallet(Params(), *chain, WalletLocation(), | |||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
// Add coins. | // Add coins. | ||||
std::vector<OutputGroup> groups; | std::vector<OutputGroup> groups; | ||||
for (int i = 0; i < 1000; ++i) { | for (int i = 0; i < 1000; ++i) { | ||||
addCoin(1000 * COIN, wallet, groups); | addCoin(1000 * COIN, wallet, groups); | ||||
} | } | ||||
addCoin(3 * COIN, wallet, groups); | addCoin(3 * COIN, wallet, groups); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | for (int i = 0; i < utxos; ++i) { | ||||
add_coin(wallet, base + (int64_t(1) << (utxos - 1 - i)) * SATOSHI, | add_coin(wallet, base + (int64_t(1) << (utxos - 1 - i)) * SATOSHI, | ||||
2 * i + 1, utxo_pool); | 2 * i + 1, utxo_pool); | ||||
} | } | ||||
return target; | return target; | ||||
} | } | ||||
static void BnBExhaustion(benchmark::State &state) { | static void BnBExhaustion(benchmark::State &state) { | ||||
SelectParams(CBaseChainParams::REGTEST); | SelectParams(CBaseChainParams::REGTEST); | ||||
const CWallet wallet(Params(), WalletLocation(), | |||||
auto chain = interfaces::MakeChain(); | |||||
const CWallet wallet(Params(), *chain, WalletLocation(), | |||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
// Setup | // Setup | ||||
std::vector<OutputGroup> utxo_pool; | std::vector<OutputGroup> utxo_pool; | ||||
CoinSet selection; | CoinSet selection; | ||||
Amount value_ret = Amount::zero(); | Amount value_ret = Amount::zero(); | ||||
Amount not_input_fees = Amount::zero(); | Amount not_input_fees = Amount::zero(); | ||||
Show All 15 Lines |