src/bench/coin_selection.cpp
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
// to build up more complicated scenarios in order to get meaningful
// measurements of performance. From laanwj, "Wallet coin selection is probably
// 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
// either for measurements."
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
Simple benchmark for wallet coin selection. Note that it maybe be necessary
to build up more complicated scenarios in order to get meaningful
measurements of performance. From laanwj, "Wallet coin selection is probably
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
either for measurements."
Simple benchmark for wallet coin selection . Note that it maybe be necessary to build up more complicated scenarios in order to get meaningful measurements of performance . From laanwj " Wallet coin selection is probably 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 either for measurements . "
static void CoinSelection(benchmark::State &state) {
    SelectParams(CBaseChainParams::REGTEST);
    const CWallet wallet(Params(), "dummy", WalletDatabase::CreateDummy());
    LOCK(wallet.cs_wallet);
    std::vector<OutputGroup> groups;
    for (int i = 0; i < 1000; ++i) {
        addCoin(1000 * COIN, wallet, groups);
    }
    addCoin(3 * COIN, wallet, groups);
    const CoinEligibilityFilter filter_standard(1, 6, 0);
    const CoinSelectionParams coin_selection_params(
        true, 34, 148, CFeeRate(Amount::zero()), 0);
    while (state.KeepRunning()) {
        std::set<CInputCoin> setCoinsRet;
        Amount nValueRet;
        bool bnb_used;
        bool success = wallet.SelectCoinsMinConf(
            1003 * COIN, filter_standard, groups, setCoinsRet, nValueRet,
            coin_selection_params, bnb_used);
        assert(success);
        assert(nValueRet == 1003 * COIN);
        assert(setCoinsRet.size() == 2);
    }
}
static void CoinSelection ( benchmark :: State & state ) { SelectParams ( CBaseChainParams :: REGTEST ) ; const CWallet wallet ( Params ( ) , " " , WalletDatabase :: CreateDummy ( ) ) ; LOCK ( wallet . cs_wallet ) ; std :: vector < OutputGroup > groups ; for ( int i = 0 ; i < 1000 ; ++ i ) { addCoin ( 1000 * COIN , wallet , groups ) ; } addCoin ( 3 * COIN , wallet , groups ) ; const CoinEligibilityFilter filter_standard ( 1 , 6 , 0 ) ; const CoinSelectionParams coin_selection_params ( true , 34 , 148 , CFeeRate ( Amount :: zero ( ) ) , 0 ) ; while ( state . KeepRunning ( ) ) { std :: set < CInputCoin > setCoinsRet ; Amount nValueRet ; bool bnb_used ; bool success = wallet . SelectCoinsMinConf ( 1003 * COIN , filter_standard , groups , setCoinsRet , nValueRet , coin_selection_params , bnb_used ) ; assert ( success ) ; assert ( nValueRet == 1003 * COIN ) ; assert ( setCoinsRet . size ( ) == 2 ) ; } }
Simple benchmark for wallet coin selection.
Simple benchmark for wallet coin selection .
// Add coins.