merge bitcoin#18575: Remove requirement that all benches use RegTestingSetup

This commit is contained in:
Kittywhiskers Van Gogh 2020-04-09 11:47:32 -04:00
parent 978fb0b315
commit d4ffaf0a79
9 changed files with 25 additions and 13 deletions

View File

@ -14,7 +14,6 @@
#include <regex>
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
const RegTestingSetup* g_testing_setup = nullptr;
namespace {
@ -55,14 +54,11 @@ void benchmark::BenchRunner::RunAll(const Args& args)
std::vector<ankerl::nanobench::Result> benchmarkResults;
for (const auto& p : benchmarks()) {
RegTestingSetup test{};
assert(g_testing_setup == nullptr);
g_testing_setup = &test;
{
assert(::ChainActive().Height() == 0);
}
if (!std::regex_match(p.first, baseMatch, reFilter)) {
g_testing_setup = nullptr;
continue;
}
@ -82,7 +78,6 @@ void benchmark::BenchRunner::RunAll(const Args& args)
}
std::cout << bench.complexityBigO() << std::endl;
}
g_testing_setup = nullptr;
benchmarkResults.push_back(bench.results().back());
}

View File

@ -15,9 +15,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
/*
* Usage:

View File

@ -16,6 +16,7 @@
static void AssembleBlock(benchmark::Bench& bench)
{
RegTestingSetup test_setup;
const CScript redeemScript = CScript() << OP_DROP << OP_TRUE;
const CScript SCRIPT_PUB =
CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemScript))
@ -29,7 +30,7 @@ static void AssembleBlock(benchmark::Bench& bench)
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().scriptSig = scriptSig;
tx.vout.emplace_back(1337, SCRIPT_PUB);
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
@ -46,7 +47,7 @@ static void AssembleBlock(benchmark::Bench& bench)
}
bench.minEpochIterations(700).run([&] {
PrepareBlock(g_testing_setup->m_node, SCRIPT_PUB);
PrepareBlock(test_setup.m_node, SCRIPT_PUB);
});
}

View File

@ -55,6 +55,9 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CCoinsCaching(benchmark::Bench& bench)
{
const ECCVerifyHandle verify_handle;
ECC_Start();
CBasicKeyStore keystore;
CCoinsView coinsDummy;
CCoinsViewCache coins(&coinsDummy);
@ -83,6 +86,7 @@ static void CCoinsCaching(benchmark::Bench& bench)
CAmount value = coins.GetValueIn(tx_1);
assert(value == (50 + 21 + 22) * COIN);
});
ECC_Stop();
}
BENCHMARK(CCoinsCaching);

View File

@ -5,10 +5,12 @@
#include <bench/bench.h>
#include <util/system.h>
#include <checkqueue.h>
#include <key.h>
#include <prevector.h>
#include <vector>
#include <pubkey.h>
#include <random.h>
#include <vector>
static const size_t BATCHES = 101;
static const size_t BATCH_SIZE = 30;
@ -20,6 +22,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::Bench& bench)
{
const ECCVerifyHandle verify_handle;
ECC_Start();
struct PrevectorJob {
prevector<PREVECTOR_SIZE, uint8_t> p;
PrevectorJob(){
@ -59,5 +64,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
control.Wait();
});
queue.StopWorkerThreads();
ECC_Stop();
}
BENCHMARK(CCheckQueueSpeedPrevectorJob);

View File

@ -8,6 +8,7 @@
#include <consensus/validation.h>
#include <policy/policy.h>
#include <pow.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <validation.h>
@ -15,6 +16,8 @@
static void DuplicateInputs(benchmark::Bench& bench)
{
RegTestingSetup test_setup;
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
const CChainParams& chainparams = Params();

View File

@ -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::Bench& bench)
{
RegTestingSetup test_setup;
CMutableTransaction tx1 = CMutableTransaction();
tx1.vin.resize(1);
tx1.vin[0].scriptSig = CScript() << OP_1;

View File

@ -4,6 +4,7 @@
#include <bench/bench.h>
#include <policy/policy.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <vector>
@ -82,6 +83,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
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);
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {

View File

@ -14,6 +14,7 @@
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine, const uint32_t epoch_iters)
{
RegTestingSetup test_setup;
const auto& ADDRESS_WATCHONLY = ADDRESS_B58T_UNSPENDABLE;
NodeContext node;
@ -30,8 +31,8 @@ static void WalletBalance(benchmark::Bench& bench, 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.value_or(ADDRESS_WATCHONLY));
generatetoaddress(g_testing_setup->m_node, ADDRESS_WATCHONLY);
generatetoaddress(test_setup.m_node, address_mine.value_or(ADDRESS_WATCHONLY));
generatetoaddress(test_setup.m_node, ADDRESS_WATCHONLY);
}
SyncWithValidationInterfaceQueue();