Skip to content

Commit fab1170

Browse files
author
MarcoFalke
committed
bench: Remove requirement that all benches use RegTestingSetup
1 parent 54f812d commit fab1170

10 files changed

+28
-20
lines changed

src/bench/bench.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <numeric>
1616
#include <regex>
1717

18-
const RegTestingSetup* g_testing_setup = nullptr;
1918
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
2019

2120
void benchmark::ConsolePrinter::header()
@@ -115,18 +114,7 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
115114
printer.header();
116115

117116
for (const auto& p : benchmarks()) {
118-
RegTestingSetup test{};
119-
assert(g_testing_setup == nullptr);
120-
g_testing_setup = &test;
121-
{
122-
LOCK(cs_main);
123-
assert(::ChainActive().Height() == 0);
124-
const bool witness_enabled{IsWitnessEnabled(::ChainActive().Tip(), Params().GetConsensus())};
125-
assert(witness_enabled);
126-
}
127-
128117
if (!std::regex_match(p.first, baseMatch, reFilter)) {
129-
g_testing_setup = nullptr;
130118
continue;
131119
}
132120

@@ -139,7 +127,6 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
139127
p.second.func(state);
140128
}
141129
printer.result(state);
142-
g_testing_setup = nullptr;
143130
}
144131

145132
printer.footer();

src/bench/bench.h

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include <boost/preprocessor/cat.hpp>
1515
#include <boost/preprocessor/stringize.hpp>
1616

17-
struct RegTestingSetup;
18-
extern const RegTestingSetup* g_testing_setup; //!< A pointer to the current testing setup
19-
2017
// Simple micro-benchmarking framework; API mostly matches a subset of the Google Benchmark
2118
// framework (see https://github.com/google/benchmark)
2219
// Why not use the Google Benchmark framework? Because adding Yet Another Dependency

src/bench/block_assemble.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
static void AssembleBlock(benchmark::State& state)
1818
{
19+
RegTestingSetup test_setup;
1920
const std::vector<unsigned char> op_true{OP_TRUE};
2021
CScriptWitness witness;
2122
witness.stack.push_back(op_true);
@@ -30,7 +31,7 @@ static void AssembleBlock(benchmark::State& state)
3031
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
3132
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
3233
CMutableTransaction tx;
33-
tx.vin.push_back(MineBlock(g_testing_setup->m_node, SCRIPT_PUB));
34+
tx.vin.push_back(MineBlock(test_setup.m_node, SCRIPT_PUB));
3435
tx.vin.back().scriptWitness = witness;
3536
tx.vout.emplace_back(1337, SCRIPT_PUB);
3637
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
@@ -47,7 +48,7 @@ static void AssembleBlock(benchmark::State& state)
4748
}
4849

4950
while (state.KeepRunning()) {
50-
PrepareBlock(g_testing_setup->m_node, SCRIPT_PUB);
51+
PrepareBlock(test_setup.m_node, SCRIPT_PUB);
5152
}
5253
}
5354

src/bench/ccoins_caching.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
1919
static void CCoinsCaching(benchmark::State& state)
2020
{
21+
const ECCVerifyHandle verify_handle;
22+
ECC_Start();
23+
2124
FillableSigningProvider keystore;
2225
CCoinsView coinsDummy;
2326
CCoinsViewCache coins(&coinsDummy);
@@ -47,6 +50,7 @@ static void CCoinsCaching(benchmark::State& state)
4750
CAmount value = coins.GetValueIn(tx_1);
4851
assert(value == (50 + 21 + 22) * COIN);
4952
}
53+
ECC_Stop();
5054
}
5155

5256
BENCHMARK(CCoinsCaching, 170 * 1000);

src/bench/checkqueue.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include <bench/bench.h>
66
#include <checkqueue.h>
7+
#include <key.h>
78
#include <prevector.h>
9+
#include <pubkey.h>
810
#include <random.h>
911
#include <util/system.h>
1012

@@ -24,6 +26,9 @@ static const unsigned int QUEUE_BATCH_SIZE = 128;
2426
// and there is a little bit of work done between calls to Add.
2527
static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
2628
{
29+
const ECCVerifyHandle verify_handle;
30+
ECC_Start();
31+
2732
struct PrevectorJob {
2833
prevector<PREVECTOR_SIZE, uint8_t> p;
2934
PrevectorJob(){
@@ -59,5 +64,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
5964
}
6065
tg.interrupt_all();
6166
tg.join_all();
67+
ECC_Stop();
6268
}
6369
BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400);

src/bench/duplicate_inputs.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
#include <consensus/merkle.h>
88
#include <consensus/validation.h>
99
#include <pow.h>
10+
#include <test/util/setup_common.h>
1011
#include <txmempool.h>
1112
#include <validation.h>
1213

1314

1415
static void DuplicateInputs(benchmark::State& state)
1516
{
17+
RegTestingSetup test_setup;
18+
1619
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
1720

1821
const CChainParams& chainparams = Params();

src/bench/mempool_eviction.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <bench/bench.h>
66
#include <policy/policy.h>
7+
#include <test/util/setup_common.h>
78
#include <txmempool.h>
89

910

@@ -24,6 +25,8 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
2425
// unique transactions for a more meaningful performance measurement.
2526
static void MempoolEviction(benchmark::State& state)
2627
{
28+
RegTestingSetup test_setup;
29+
2730
CMutableTransaction tx1 = CMutableTransaction();
2831
tx1.vin.resize(1);
2932
tx1.vin[0].scriptSig = CScript() << OP_1;

src/bench/mempool_stress.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <bench/bench.h>
66
#include <policy/policy.h>
7+
#include <test/util/setup_common.h>
78
#include <txmempool.h>
89

910
#include <vector>
@@ -73,6 +74,7 @@ static void ComplexMemPool(benchmark::State& state)
7374
ordered_coins.emplace_back(MakeTransactionRef(tx));
7475
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
7576
}
77+
TestingSetup test_setup;
7678
CTxMemPool pool;
7779
LOCK2(cs_main, pool.cs);
7880
while (state.KeepRunning()) {

src/bench/verify_script.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// modified to measure performance of other types of scripts.
1919
static void VerifyScriptBench(benchmark::State& state)
2020
{
21+
const ECCVerifyHandle verify_handle;
22+
ECC_Start();
23+
2124
const int flags = SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH;
2225
const int witnessversion = 0;
2326

@@ -69,6 +72,7 @@ static void VerifyScriptBench(benchmark::State& state)
6972
assert(csuccess == 1);
7073
#endif
7174
}
75+
ECC_Stop();
7276
}
7377

7478
static void VerifyNestedIfScript(benchmark::State& state) {

src/bench/wallet_balance.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
static void WalletBalance(benchmark::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine)
1616
{
17+
RegTestingSetup test_setup;
1718
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
1819

1920
NodeContext node;
@@ -30,8 +31,8 @@ static void WalletBalance(benchmark::State& state, const bool set_dirty, const b
3031
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
3132

3233
for (int i = 0; i < 100; ++i) {
33-
generatetoaddress(g_testing_setup->m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
34-
generatetoaddress(g_testing_setup->m_node, ADDRESS_WATCHONLY);
34+
generatetoaddress(test_setup.m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
35+
generatetoaddress(test_setup.m_node, ADDRESS_WATCHONLY);
3536
}
3637
SyncWithValidationInterfaceQueue();
3738

0 commit comments

Comments
 (0)