From 18dacf9bd25154e184b097ee4e8f786d9be25637 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Sun, 2 Oct 2016 17:38:48 -0400 Subject: Add microbenchmarks to profile more code paths. The new benchmarks exercise script validation, CCoinsDBView caching, mempool eviction, and wallet coin selection code. All of the benchmarks added here are extremely simple and don't necessarily mirror common real world conditions or interesting performance edge cases. Details about how specific benchmarks can be improved are noted in comments. Github-Issue: #7883 --- src/bench/coin_selection.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bench/coin_selection.cpp (limited to 'src/bench/coin_selection.cpp') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp new file mode 100644 index 000000000..7091ee3e1 --- /dev/null +++ b/src/bench/coin_selection.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2012-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "bench.h" +#include "wallet/wallet.h" + +#include +#include + +using namespace std; + +static void addCoin(const CAmount& nValue, const CWallet& wallet, vector& vCoins) +{ + int nInput = 0; + + static int nextLockTime = 0; + CMutableTransaction tx; + tx.nLockTime = nextLockTime++; // so all transactions get different hashes + tx.vout.resize(nInput + 1); + tx.vout[nInput].nValue = nValue; + CWalletTx* wtx = new CWalletTx(&wallet, tx); + + int nAge = 6 * 24; + COutput output(wtx, nInput, nAge, true, true); + vCoins.push_back(output); +} + +// 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) +static void CoinSelection(benchmark::State& state) +{ + const CWallet wallet; + vector vCoins; + LOCK(wallet.cs_wallet); + + while (state.KeepRunning()) { + // Empty wallet. + BOOST_FOREACH (COutput output, vCoins) + delete output.tx; + vCoins.clear(); + + // Add coins. + for (int i = 0; i < 1000; i++) + addCoin(1000 * COIN, wallet, vCoins); + addCoin(3 * COIN, wallet, vCoins); + + set > setCoinsRet; + CAmount nValueRet; + bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, vCoins, setCoinsRet, nValueRet); + assert(success); + assert(nValueRet == 1003 * COIN); + assert(setCoinsRet.size() == 2); + } +} + +BENCHMARK(CoinSelection); -- cgit v1.2.3 From c3f5673a6304e3ea9fa56fff66b6ea1cb73cc98f Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 11 Nov 2016 16:54:51 -0800 Subject: Make CWalletTx store a CTransactionRef instead of inheriting --- src/bench/coin_selection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bench/coin_selection.cpp') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 7091ee3e1..32690fe48 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -19,7 +19,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, vector Date: Fri, 2 Dec 2016 15:29:20 -0500 Subject: SelectCoinsMinConf: Prefer coins with fewer ancestors --- src/bench/coin_selection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bench/coin_selection.cpp') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 7091ee3e1..ce1ce511e 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -52,7 +52,7 @@ static void CoinSelection(benchmark::State& state) set > setCoinsRet; CAmount nValueRet; - bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, vCoins, setCoinsRet, nValueRet); + bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet); assert(success); assert(nValueRet == 1003 * COIN); assert(setCoinsRet.size() == 2); -- cgit v1.2.3 From 27765b6403cece54320374b37afb01a0cfe571c3 Mon Sep 17 00:00:00 2001 From: isle2983 Date: Sat, 31 Dec 2016 11:01:21 -0700 Subject: Increment MIT Licence copyright header year on files modified in 2016 Edited via: $ contrib/devtools/copyright_header.py update . --- src/bench/coin_selection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bench/coin_selection.cpp') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index cacead4a5..c961151f5 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2015 The Bitcoin Core developers +// Copyright (c) 2012-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From 73f41190b91dce9c125b1828b18f7625e0200145 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Mon, 5 Dec 2016 16:03:53 +0900 Subject: Refactoring: Removed using namespace from bench/ and test/ source files. --- src/bench/coin_selection.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/bench/coin_selection.cpp') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index cacead4a5..9db6492e5 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -8,9 +8,7 @@ #include #include -using namespace std; - -static void addCoin(const CAmount& nValue, const CWallet& wallet, vector& vCoins) +static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector& vCoins) { int nInput = 0; @@ -36,7 +34,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, vector vCoins; + std::vector vCoins; LOCK(wallet.cs_wallet); while (state.KeepRunning()) { @@ -50,7 +48,7 @@ static void CoinSelection(benchmark::State& state) addCoin(1000 * COIN, wallet, vCoins); addCoin(3 * COIN, wallet, vCoins); - set > setCoinsRet; + std::set > setCoinsRet; CAmount nValueRet; bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet); assert(success); -- cgit v1.2.3