aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-04-22 10:52:05 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-04-22 10:52:40 -0400
commita7a6f1ff417abc2452a2a2b9edcd2f12d6c14441 (patch)
tree35e4072eb47d8af712986a128359566a0d64c745 /src
parent5dcb0615898216c503e965a01d855a5999a586b5 (diff)
parentfa1fdb02fccd0f670f7b08ee61c249f04d0db17f (diff)
Merge #18575: bench: Remove requirement that all benches use same testing setup
fa1fdb02fccd0f670f7b08ee61c249f04d0db17f bench: Replace ::mempool globabl with test_setup.mempool (MarcoFalke) fab117096446ab63d1f38c1ef6edbc94a5d4ab52 bench: Remove requirement that all benches use RegTestingSetup (MarcoFalke) Pull request description: The benches have always set up one global testing setup. This makes it hard to pick no testing setup at all or one with different params. Fix this by removing any global state setup from the main `bench.cpp` and leave the setup to each individual bench. One reason to have one global testing setup is to set the datadir location to a tempdir to avoid reading or writing in the default datadir location. But #13687 should prevent this already. Top commit has no ACKs. Tree-SHA512: 7c98aea7725a20f4b9225221f4279b9e9f7257ed5c14712ad01ea80d87c3b0fed760b40f413892498bbb354a917ee02d4c575cbe8423a403b86755e8ee11f33b
Diffstat (limited to 'src')
-rw-r--r--src/bench/bench.cpp13
-rw-r--r--src/bench/bench.h3
-rw-r--r--src/bench/block_assemble.cpp7
-rw-r--r--src/bench/ccoins_caching.cpp4
-rw-r--r--src/bench/checkqueue.cpp6
-rw-r--r--src/bench/duplicate_inputs.cpp3
-rw-r--r--src/bench/mempool_eviction.cpp3
-rw-r--r--src/bench/mempool_stress.cpp2
-rw-r--r--src/bench/verify_script.cpp4
-rw-r--r--src/bench/wallet_balance.cpp5
10 files changed, 29 insertions, 21 deletions
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 55a9e0fe42..7b93ef688d 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -15,7 +15,6 @@
#include <numeric>
#include <regex>
-const RegTestingSetup* g_testing_setup = nullptr;
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
void benchmark::ConsolePrinter::header()
@@ -115,18 +114,7 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
printer.header();
for (const auto& p : benchmarks()) {
- RegTestingSetup test{};
- assert(g_testing_setup == nullptr);
- g_testing_setup = &test;
- {
- LOCK(cs_main);
- assert(::ChainActive().Height() == 0);
- const bool witness_enabled{IsWitnessEnabled(::ChainActive().Tip(), Params().GetConsensus())};
- assert(witness_enabled);
- }
-
if (!std::regex_match(p.first, baseMatch, reFilter)) {
- g_testing_setup = nullptr;
continue;
}
@@ -139,7 +127,6 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
p.second.func(state);
}
printer.result(state);
- g_testing_setup = nullptr;
}
printer.footer();
diff --git a/src/bench/bench.h b/src/bench/bench.h
index 0a0fa99c67..629bca9a73 100644
--- a/src/bench/bench.h
+++ b/src/bench/bench.h
@@ -14,9 +14,6 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
-struct RegTestingSetup;
-extern const RegTestingSetup* g_testing_setup; //!< A pointer to the current testing setup
-
// Simple micro-benchmarking framework; API mostly matches a subset of the Google Benchmark
// framework (see https://github.com/google/benchmark)
// Why not use the Google Benchmark framework? Because adding Yet Another Dependency
diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp
index a113a73828..1a0084c915 100644
--- a/src/bench/block_assemble.cpp
+++ b/src/bench/block_assemble.cpp
@@ -16,6 +16,7 @@
static void AssembleBlock(benchmark::State& state)
{
+ RegTestingSetup test_setup;
const std::vector<unsigned char> op_true{OP_TRUE};
CScriptWitness witness;
witness.stack.push_back(op_true);
@@ -30,7 +31,7 @@ static void AssembleBlock(benchmark::State& state)
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
CMutableTransaction tx;
- tx.vin.push_back(MineBlock(g_testing_setup->m_node, SCRIPT_PUB));
+ tx.vin.push_back(MineBlock(test_setup.m_node, SCRIPT_PUB));
tx.vin.back().scriptWitness = witness;
tx.vout.emplace_back(1337, SCRIPT_PUB);
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
@@ -41,13 +42,13 @@ static void AssembleBlock(benchmark::State& state)
for (const auto& txr : txs) {
TxValidationState state;
- bool ret{::AcceptToMemoryPool(::mempool, state, txr, nullptr /* plTxnReplaced */, false /* bypass_limits */, /* nAbsurdFee */ 0)};
+ bool ret{::AcceptToMemoryPool(*test_setup.m_node.mempool, state, txr, nullptr /* plTxnReplaced */, false /* bypass_limits */, /* nAbsurdFee */ 0)};
assert(ret);
}
}
while (state.KeepRunning()) {
- PrepareBlock(g_testing_setup->m_node, SCRIPT_PUB);
+ PrepareBlock(test_setup.m_node, SCRIPT_PUB);
}
}
diff --git a/src/bench/ccoins_caching.cpp b/src/bench/ccoins_caching.cpp
index fb00189fe1..d658976c3c 100644
--- a/src/bench/ccoins_caching.cpp
+++ b/src/bench/ccoins_caching.cpp
@@ -18,6 +18,9 @@
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CCoinsCaching(benchmark::State& state)
{
+ const ECCVerifyHandle verify_handle;
+ ECC_Start();
+
FillableSigningProvider keystore;
CCoinsView coinsDummy;
CCoinsViewCache coins(&coinsDummy);
@@ -47,6 +50,7 @@ static void CCoinsCaching(benchmark::State& state)
CAmount value = coins.GetValueIn(tx_1);
assert(value == (50 + 21 + 22) * COIN);
}
+ ECC_Stop();
}
BENCHMARK(CCoinsCaching, 170 * 1000);
diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp
index 6b2c527e52..e052681181 100644
--- a/src/bench/checkqueue.cpp
+++ b/src/bench/checkqueue.cpp
@@ -4,7 +4,9 @@
#include <bench/bench.h>
#include <checkqueue.h>
+#include <key.h>
#include <prevector.h>
+#include <pubkey.h>
#include <random.h>
#include <util/system.h>
@@ -24,6 +26,9 @@ static const unsigned int QUEUE_BATCH_SIZE = 128;
// and there is a little bit of work done between calls to Add.
static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
{
+ const ECCVerifyHandle verify_handle;
+ ECC_Start();
+
struct PrevectorJob {
prevector<PREVECTOR_SIZE, uint8_t> p;
PrevectorJob(){
@@ -59,5 +64,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
}
tg.interrupt_all();
tg.join_all();
+ ECC_Stop();
}
BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400);
diff --git a/src/bench/duplicate_inputs.cpp b/src/bench/duplicate_inputs.cpp
index 83f279b008..57673ccb84 100644
--- a/src/bench/duplicate_inputs.cpp
+++ b/src/bench/duplicate_inputs.cpp
@@ -7,12 +7,15 @@
#include <consensus/merkle.h>
#include <consensus/validation.h>
#include <pow.h>
+#include <test/util/setup_common.h>
#include <txmempool.h>
#include <validation.h>
static void DuplicateInputs(benchmark::State& state)
{
+ RegTestingSetup test_setup;
+
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
const CChainParams& chainparams = Params();
diff --git a/src/bench/mempool_eviction.cpp b/src/bench/mempool_eviction.cpp
index 1c9c106666..7df024def6 100644
--- a/src/bench/mempool_eviction.cpp
+++ b/src/bench/mempool_eviction.cpp
@@ -4,6 +4,7 @@
#include <bench/bench.h>
#include <policy/policy.h>
+#include <test/util/setup_common.h>
#include <txmempool.h>
@@ -24,6 +25,8 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
// unique transactions for a more meaningful performance measurement.
static void MempoolEviction(benchmark::State& state)
{
+ RegTestingSetup test_setup;
+
CMutableTransaction tx1 = CMutableTransaction();
tx1.vin.resize(1);
tx1.vin[0].scriptSig = CScript() << OP_1;
diff --git a/src/bench/mempool_stress.cpp b/src/bench/mempool_stress.cpp
index 389e2c096f..38d8632318 100644
--- a/src/bench/mempool_stress.cpp
+++ b/src/bench/mempool_stress.cpp
@@ -4,6 +4,7 @@
#include <bench/bench.h>
#include <policy/policy.h>
+#include <test/util/setup_common.h>
#include <txmempool.h>
#include <vector>
@@ -73,6 +74,7 @@ static void ComplexMemPool(benchmark::State& state)
ordered_coins.emplace_back(MakeTransactionRef(tx));
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
}
+ TestingSetup test_setup;
CTxMemPool pool;
LOCK2(cs_main, pool.cs);
while (state.KeepRunning()) {
diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp
index 5ed8309b65..14bca5f7d1 100644
--- a/src/bench/verify_script.cpp
+++ b/src/bench/verify_script.cpp
@@ -18,6 +18,9 @@
// modified to measure performance of other types of scripts.
static void VerifyScriptBench(benchmark::State& state)
{
+ const ECCVerifyHandle verify_handle;
+ ECC_Start();
+
const int flags = SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH;
const int witnessversion = 0;
@@ -69,6 +72,7 @@ static void VerifyScriptBench(benchmark::State& state)
assert(csuccess == 1);
#endif
}
+ ECC_Stop();
}
static void VerifyNestedIfScript(benchmark::State& state) {
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index 8be0aab1ff..05d61fca22 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -14,6 +14,7 @@
static void WalletBalance(benchmark::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine)
{
+ RegTestingSetup test_setup;
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
NodeContext node;
@@ -30,8 +31,8 @@ static void WalletBalance(benchmark::State& state, const bool set_dirty, const b
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
for (int i = 0; i < 100; ++i) {
- generatetoaddress(g_testing_setup->m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
- generatetoaddress(g_testing_setup->m_node, ADDRESS_WATCHONLY);
+ generatetoaddress(test_setup.m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
+ generatetoaddress(test_setup.m_node, ADDRESS_WATCHONLY);
}
SyncWithValidationInterfaceQueue();