Changeset View
Changeset View
Standalone View
Standalone View
src/bench/wallet_balance.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <test/util/mining.h> | #include <test/util/mining.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <test/util/wallet.h> | #include <test/util/wallet.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
static void WalletBalance(benchmark::State &state, const bool set_dirty, | static void WalletBalance(benchmark::Bench &bench, const bool set_dirty, | ||||
const bool add_watchonly, const bool add_mine) { | const bool add_watchonly, const bool add_mine) { | ||||
TestingSetup test_setup{ | TestingSetup test_setup{ | ||||
CBaseChainParams::REGTEST, | CBaseChainParams::REGTEST, | ||||
/* extra_args */ | /* extra_args */ | ||||
{ | { | ||||
"-nodebuglogfile", | "-nodebuglogfile", | ||||
"-nodebug", | "-nodebug", | ||||
}, | }, | ||||
Show All 29 Lines | for (int i = 0; i < 100; ++i) { | ||||
address_mine.value_or(ADDRESS_WATCHONLY)); | address_mine.value_or(ADDRESS_WATCHONLY)); | ||||
generatetoaddress(config, test_setup.m_node, ADDRESS_WATCHONLY); | generatetoaddress(config, test_setup.m_node, ADDRESS_WATCHONLY); | ||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
// Cache | // Cache | ||||
auto bal = wallet.GetBalance(); | auto bal = wallet.GetBalance(); | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
if (set_dirty) { | if (set_dirty) { | ||||
wallet.MarkDirty(); | wallet.MarkDirty(); | ||||
} | } | ||||
bal = wallet.GetBalance(); | bal = wallet.GetBalance(); | ||||
if (add_mine) { | if (add_mine) { | ||||
assert(bal.m_mine_trusted > Amount::zero()); | assert(bal.m_mine_trusted > Amount::zero()); | ||||
} | } | ||||
if (add_watchonly) { | if (add_watchonly) { | ||||
assert(bal.m_watchonly_trusted > Amount::zero()); | assert(bal.m_watchonly_trusted > Amount::zero()); | ||||
} | } | ||||
} | }); | ||||
} | } | ||||
static void WalletBalanceDirty(benchmark::State &state) { | static void WalletBalanceDirty(benchmark::Bench &bench) { | ||||
WalletBalance(state, /* set_dirty */ true, /* add_watchonly */ true, | WalletBalance(bench, /* set_dirty */ true, /* add_watchonly */ true, | ||||
/* add_mine */ true); | /* add_mine */ true); | ||||
} | } | ||||
static void WalletBalanceClean(benchmark::State &state) { | static void WalletBalanceClean(benchmark::Bench &bench) { | ||||
WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ true, | WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ true, | ||||
/* add_mine */ true); | /* add_mine */ true); | ||||
} | } | ||||
static void WalletBalanceMine(benchmark::State &state) { | static void WalletBalanceMine(benchmark::Bench &bench) { | ||||
WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ false, | WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ false, | ||||
/* add_mine */ true); | /* add_mine */ true); | ||||
} | } | ||||
static void WalletBalanceWatch(benchmark::State &state) { | static void WalletBalanceWatch(benchmark::Bench &bench) { | ||||
WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ true, | WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ true, | ||||
/* add_mine */ false); | /* add_mine */ false); | ||||
} | } | ||||
BENCHMARK(WalletBalanceDirty, 2500); | BENCHMARK(WalletBalanceDirty); | ||||
BENCHMARK(WalletBalanceClean, 8000); | BENCHMARK(WalletBalanceClean); | ||||
BENCHMARK(WalletBalanceMine, 16000); | BENCHMARK(WalletBalanceMine); | ||||
BENCHMARK(WalletBalanceWatch, 8000); | BENCHMARK(WalletBalanceWatch); |