Skip to content

Commit bb4554c

Browse files
committed
bench: add benchmark for wallet creation procedure
1 parent 22025d0 commit bb4554c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ endif
8484
if ENABLE_WALLET
8585
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
8686
bench_bench_bitcoin_SOURCES += bench/wallet_balance.cpp
87+
bench_bench_bitcoin_SOURCES += bench/wallet_create.cpp
8788
bench_bench_bitcoin_SOURCES += bench/wallet_loading.cpp
8889
bench_bench_bitcoin_SOURCES += bench/wallet_create_tx.cpp
8990
bench_bench_bitcoin_LDADD += $(BDB_LIBS) $(SQLITE_LIBS)

src/bench/wallet_create.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2023-present The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/bench.h>
6+
#include <node/context.h>
7+
#include <random.h>
8+
#include <test/util/setup_common.h>
9+
#include <wallet/context.h>
10+
#include <wallet/wallet.h>
11+
12+
namespace wallet {
13+
static void WalletCreate(benchmark::Bench& bench, bool encrypted)
14+
{
15+
auto test_setup = MakeNoLogFileContext<TestingSetup>();
16+
FastRandomContext random;
17+
18+
WalletContext context;
19+
context.args = &test_setup->m_args;
20+
context.chain = test_setup->m_node.chain.get();
21+
22+
DatabaseOptions options;
23+
options.require_format = DatabaseFormat::SQLITE;
24+
options.require_create = true;
25+
options.create_flags = WALLET_FLAG_DESCRIPTORS;
26+
27+
if (encrypted) {
28+
options.create_passphrase = random.rand256().ToString();
29+
}
30+
31+
DatabaseStatus status;
32+
bilingual_str error_string;
33+
std::vector<bilingual_str> warnings;
34+
35+
fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
36+
bench.run([&] {
37+
auto wallet = CreateWallet(context, wallet_path.u8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
38+
assert(status == DatabaseStatus::SUCCESS);
39+
assert(wallet != nullptr);
40+
41+
// Cleanup
42+
wallet.reset();
43+
fs::remove_all(wallet_path);
44+
});
45+
}
46+
47+
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
48+
static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
49+
50+
#ifdef USE_SQLITE
51+
BENCHMARK(WalletCreatePlain, benchmark::PriorityLevel::LOW);
52+
BENCHMARK(WalletCreateEncrypted, benchmark::PriorityLevel::LOW);
53+
#endif
54+
55+
} // namespace wallet

0 commit comments

Comments
 (0)