Skip to content

Commit

Permalink
bench: Remove requirement that all benches use RegTestingSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Apr 17, 2020
1 parent 54f812d commit fab1170
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 20 deletions.
13 changes: 0 additions & 13 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/bench/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -47,7 +48,7 @@ static void AssembleBlock(benchmark::State& state)
}

while (state.KeepRunning()) {
PrepareBlock(g_testing_setup->m_node, SCRIPT_PUB);
PrepareBlock(test_setup.m_node, SCRIPT_PUB);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/bench/ccoins_caching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
6 changes: 6 additions & 0 deletions src/bench/checkqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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(){
Expand Down Expand Up @@ -59,5 +64,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
}
tg.interrupt_all();
tg.join_all();
ECC_Stop();
}
BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400);
3 changes: 3 additions & 0 deletions src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/bench/mempool_eviction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <bench/bench.h>
#include <policy/policy.h>
#include <test/util/setup_common.h>
#include <txmempool.h>


Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <bench/bench.h>
#include <policy/policy.h>
#include <test/util/setup_common.h>
#include <txmempool.h>

#include <vector>
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 4 additions & 0 deletions src/bench/verify_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,6 +72,7 @@ static void VerifyScriptBench(benchmark::State& state)
assert(csuccess == 1);
#endif
}
ECC_Stop();
}

static void VerifyNestedIfScript(benchmark::State& state) {
Expand Down
5 changes: 3 additions & 2 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit fab1170

Please sign in to comment.