diff options
Diffstat (limited to 'src/bench')
-rw-r--r-- | src/bench/base58.cpp | 2 | ||||
-rw-r--r-- | src/bench/bech32.cpp | 37 | ||||
-rw-r--r-- | src/bench/bench.cpp | 2 | ||||
-rw-r--r-- | src/bench/bench.h | 2 | ||||
-rw-r--r-- | src/bench/bench_bitcoin.cpp | 15 | ||||
-rw-r--r-- | src/bench/block_assemble.cpp | 14 | ||||
-rw-r--r-- | src/bench/ccoins_caching.cpp | 2 | ||||
-rw-r--r-- | src/bench/checkblock.cpp | 2 | ||||
-rw-r--r-- | src/bench/checkqueue.cpp | 2 | ||||
-rw-r--r-- | src/bench/coin_selection.cpp | 26 | ||||
-rw-r--r-- | src/bench/crypto_hash.cpp | 2 | ||||
-rw-r--r-- | src/bench/examples.cpp | 2 | ||||
-rw-r--r-- | src/bench/lockedpool.cpp | 2 | ||||
-rw-r--r-- | src/bench/mempool_eviction.cpp | 5 | ||||
-rw-r--r-- | src/bench/merkle_root.cpp | 2 | ||||
-rw-r--r-- | src/bench/prevector.cpp | 30 | ||||
-rw-r--r-- | src/bench/rollingbloom.cpp | 2 | ||||
-rw-r--r-- | src/bench/verify_script.cpp | 4 |
18 files changed, 120 insertions, 33 deletions
diff --git a/src/bench/base58.cpp b/src/bench/base58.cpp index 70bfd7d0bf..a555376e40 100644 --- a/src/bench/base58.cpp +++ b/src/bench/base58.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/bech32.cpp b/src/bench/bech32.cpp new file mode 100644 index 0000000000..8b80e17391 --- /dev/null +++ b/src/bench/bech32.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2018 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/bench.h> + +#include <validation.h> +#include <bech32.h> +#include <utilstrencodings.h> + +#include <vector> +#include <string> + + +static void Bech32Encode(benchmark::State& state) +{ + std::vector<uint8_t> v = ParseHex("c97f5a67ec381b760aeaf67573bc164845ff39a3bb26a1cee401ac67243b48db"); + std::vector<unsigned char> tmp = {0}; + tmp.reserve(1 + 32 * 8 / 5); + ConvertBits<8, 5, true>([&](unsigned char c) { tmp.push_back(c); }, v.begin(), v.end()); + while (state.KeepRunning()) { + bech32::Encode("bc", tmp); + } +} + + +static void Bech32Decode(benchmark::State& state) +{ + std::string addr = "bc1qkallence7tjawwvy0dwt4twc62qjgaw8f4vlhyd006d99f09"; + while (state.KeepRunning()) { + bech32::Decode(addr); + } +} + + +BENCHMARK(Bech32Encode, 800 * 1000); +BENCHMARK(Bech32Decode, 800 * 1000); diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index de3e57b04f..966b99f6c8 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/bench.h b/src/bench/bench.h index 5d131c2aa8..35eeab3393 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index f3302bfe5a..603b858e54 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -38,6 +38,14 @@ static void SetupBenchArgs() gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); } +static fs::path SetDataDir() +{ + fs::path ret = fs::temp_directory_path() / "bench_bitcoin" / fs::unique_path(); + fs::create_directories(ret); + gArgs.ForceSetArg("-datadir", ret.string()); + return ret; +} + int main(int argc, char** argv) { SetupBenchArgs(); @@ -53,6 +61,9 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } + // Set the datadir after parsing the bench options + const fs::path bench_datadir{SetDataDir()}; + SHA256AutoDetect(); RandomInit(); ECC_Start(); @@ -80,6 +91,8 @@ int main(int argc, char** argv) benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only); + fs::remove_all(bench_datadir); + ECC_Stop(); return EXIT_SUCCESS; diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 2bd67654ab..bc99b8cdcd 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2017 The Bitcoin Core developers +// Copyright (c) 2011-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -98,10 +98,14 @@ static void AssembleBlock(benchmark::State& state) if (NUM_BLOCKS - b >= COINBASE_MATURITY) txs.at(b) = MakeTransactionRef(tx); } - for (const auto& txr : txs) { - CValidationState state; - bool ret{::AcceptToMemoryPool(::mempool, state, txr, nullptr /* pfMissingInputs */, nullptr /* plTxnReplaced */, false /* bypass_limits */, /* nAbsurdFee */ 0)}; - assert(ret); + { + LOCK(::cs_main); // Required for ::AcceptToMemoryPool. + + for (const auto& txr : txs) { + CValidationState state; + bool ret{::AcceptToMemoryPool(::mempool, state, txr, nullptr /* pfMissingInputs */, nullptr /* plTxnReplaced */, false /* bypass_limits */, /* nAbsurdFee */ 0)}; + assert(ret); + } } while (state.KeepRunning()) { diff --git a/src/bench/ccoins_caching.cpp b/src/bench/ccoins_caching.cpp index 74169bcad7..db303eeead 100644 --- a/src/bench/ccoins_caching.cpp +++ b/src/bench/ccoins_caching.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 387ae1769c..6f03581c4b 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index 6e816f1bec..79689f6e0b 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index f3180809b5..0a6f5d85ea 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2017 The Bitcoin Core developers +// Copyright (c) 2012-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -8,7 +8,7 @@ #include <set> -static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<COutput>& vCoins) +static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<OutputGroup>& groups) { int nInput = 0; @@ -21,7 +21,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<CO int nAge = 6 * 24; COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */); - vCoins.push_back(output); + groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0); } // Simple benchmark for wallet coin selection. Note that it maybe be necessary @@ -37,11 +37,11 @@ static void CoinSelection(benchmark::State& state) LOCK(wallet.cs_wallet); // Add coins. - std::vector<COutput> vCoins; + std::vector<OutputGroup> groups; for (int i = 0; i < 1000; ++i) { - addCoin(1000 * COIN, wallet, vCoins); + addCoin(1000 * COIN, wallet, groups); } - addCoin(3 * COIN, wallet, vCoins); + addCoin(3 * COIN, wallet, groups); const CoinEligibilityFilter filter_standard(1, 6, 0); const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0); @@ -49,7 +49,7 @@ static void CoinSelection(benchmark::State& state) std::set<CInputCoin> setCoinsRet; CAmount nValueRet; bool bnb_used; - bool success = wallet.SelectCoinsMinConf(1003 * COIN, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params, 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); @@ -57,17 +57,21 @@ static void CoinSelection(benchmark::State& state) } typedef std::set<CInputCoin> CoinSet; +static const CWallet testWallet("dummy", WalletDatabase::CreateDummy()); +std::vector<std::unique_ptr<CWalletTx>> wtxn; // Copied from src/wallet/test/coinselector_tests.cpp -static void add_coin(const CAmount& nValue, int nInput, std::vector<CInputCoin>& set) +static void add_coin(const CAmount& nValue, int nInput, std::vector<OutputGroup>& set) { CMutableTransaction tx; tx.vout.resize(nInput + 1); tx.vout[nInput].nValue = nValue; - set.emplace_back(MakeTransactionRef(tx), nInput); + std::unique_ptr<CWalletTx> wtx(new CWalletTx(&testWallet, MakeTransactionRef(std::move(tx)))); + set.emplace_back(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0); + wtxn.emplace_back(std::move(wtx)); } // Copied from src/wallet/test/coinselector_tests.cpp -static CAmount make_hard_case(int utxos, std::vector<CInputCoin>& utxo_pool) +static CAmount make_hard_case(int utxos, std::vector<OutputGroup>& utxo_pool) { utxo_pool.clear(); CAmount target = 0; @@ -82,7 +86,7 @@ static CAmount make_hard_case(int utxos, std::vector<CInputCoin>& utxo_pool) static void BnBExhaustion(benchmark::State& state) { // Setup - std::vector<CInputCoin> utxo_pool; + std::vector<OutputGroup> utxo_pool; CoinSet selection; CAmount value_ret = 0; CAmount not_input_fees = 0; diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 7d907eaf10..bab22f5984 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/examples.cpp b/src/bench/examples.cpp index b68c9cd156..6d95e05ef6 100644 --- a/src/bench/examples.cpp +++ b/src/bench/examples.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/lockedpool.cpp b/src/bench/lockedpool.cpp index 55a00318c1..0712eab4bc 100644 --- a/src/bench/lockedpool.cpp +++ b/src/bench/lockedpool.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/mempool_eviction.cpp b/src/bench/mempool_eviction.cpp index 4c947a519f..0ec7c158cc 100644 --- a/src/bench/mempool_eviction.cpp +++ b/src/bench/mempool_eviction.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2017 The Bitcoin Core developers +// Copyright (c) 2011-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -9,7 +9,7 @@ #include <list> #include <vector> -static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool) +static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs) { int64_t nTime = 0; unsigned int nHeight = 1; @@ -108,6 +108,7 @@ static void MempoolEviction(benchmark::State& state) tx7.vout[1].nValue = 10 * COIN; CTxMemPool pool; + LOCK(pool.cs); // Create transaction references outside the "hot loop" const CTransactionRef tx1_r{MakeTransactionRef(tx1)}; const CTransactionRef tx2_r{MakeTransactionRef(tx2)}; diff --git a/src/bench/merkle_root.cpp b/src/bench/merkle_root.cpp index fab12da311..bdb2bdbe3d 100644 --- a/src/bench/merkle_root.cpp +++ b/src/bench/merkle_root.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 09c7020848..8cc404b9e2 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -1,15 +1,20 @@ -// Copyright (c) 2015-2017 The Bitcoin Core developers +// Copyright (c) 2015-2018 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 <compat.h> #include <prevector.h> +#include <serialize.h> +#include <streams.h> #include <bench/bench.h> struct nontrivial_t { int x; nontrivial_t() :x(-1) {} + ADD_SERIALIZE_METHODS + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action) {READWRITE(x);} }; static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value, "expected nontrivial_t to not be trivially constructible"); @@ -62,6 +67,28 @@ static void PrevectorResize(benchmark::State& state) } } +template <typename T> +static void PrevectorDeserialize(benchmark::State& state) +{ + CDataStream s0(SER_NETWORK, 0); + prevector<28, T> t0; + t0.resize(28); + for (auto x = 0; x < 900; ++x) { + s0 << t0; + } + t0.resize(100); + for (auto x = 0; x < 101; ++x) { + s0 << t0; + } + while (state.KeepRunning()) { + prevector<28, T> t1; + for (auto x = 0; x < 1000; ++x) { + s0 >> t1; + } + s0.Init(SER_NETWORK, 0); + } +} + #define PREVECTOR_TEST(name, nontrivops, trivops) \ static void Prevector ## name ## Nontrivial(benchmark::State& state) { \ Prevector ## name<nontrivial_t>(state); \ @@ -75,3 +102,4 @@ static void PrevectorResize(benchmark::State& state) PREVECTOR_TEST(Clear, 28300, 88600) PREVECTOR_TEST(Destructor, 28800, 88900) PREVECTOR_TEST(Resize, 28900, 90300) +PREVECTOR_TEST(Deserialize, 6800, 52000) diff --git a/src/bench/rollingbloom.cpp b/src/bench/rollingbloom.cpp index f7f72605d7..43e7635047 100644 --- a/src/bench/rollingbloom.cpp +++ b/src/bench/rollingbloom.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp index ae60588c2d..312b66e38a 100644 --- a/src/bench/verify_script.cpp +++ b/src/bench/verify_script.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Bitcoin Core developers +// Copyright (c) 2016-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -76,7 +76,7 @@ static void VerifyScriptBench(benchmark::State& state) CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, txCredit); CScriptWitness& witness = txSpend.vin[0].scriptWitness; witness.stack.emplace_back(); - key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back(), 0); + key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back()); witness.stack.back().push_back(static_cast<unsigned char>(SIGHASH_ALL)); witness.stack.push_back(ToByteVector(pubkey)); |