diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-11-16 11:15:08 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2023-11-16 11:27:17 -0300 |
commit | bb4554c81e0d819d74996f89cbb9c00476aedf8c (patch) | |
tree | bc8b73571b21843096d9dc8fd03dbdf2db6ed55f /src/bench/wallet_create.cpp | |
parent | 22025d06e53f9bfccf88c600815f1cc496595d5d (diff) |
bench: add benchmark for wallet creation procedure
Diffstat (limited to 'src/bench/wallet_create.cpp')
-rw-r--r-- | src/bench/wallet_create.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/bench/wallet_create.cpp b/src/bench/wallet_create.cpp new file mode 100644 index 0000000000..ba3c25d25e --- /dev/null +++ b/src/bench/wallet_create.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2023-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or https://www.opensource.org/licenses/mit-license.php. + +#include <bench/bench.h> +#include <node/context.h> +#include <random.h> +#include <test/util/setup_common.h> +#include <wallet/context.h> +#include <wallet/wallet.h> + +namespace wallet { +static void WalletCreate(benchmark::Bench& bench, bool encrypted) +{ + auto test_setup = MakeNoLogFileContext<TestingSetup>(); + FastRandomContext random; + + WalletContext context; + context.args = &test_setup->m_args; + context.chain = test_setup->m_node.chain.get(); + + DatabaseOptions options; + options.require_format = DatabaseFormat::SQLITE; + options.require_create = true; + options.create_flags = WALLET_FLAG_DESCRIPTORS; + + if (encrypted) { + options.create_passphrase = random.rand256().ToString(); + } + + DatabaseStatus status; + bilingual_str error_string; + std::vector<bilingual_str> warnings; + + fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str(); + bench.run([&] { + auto wallet = CreateWallet(context, wallet_path.u8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings); + assert(status == DatabaseStatus::SUCCESS); + assert(wallet != nullptr); + + // Cleanup + wallet.reset(); + fs::remove_all(wallet_path); + }); +} + +static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); } +static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); } + +#ifdef USE_SQLITE +BENCHMARK(WalletCreatePlain, benchmark::PriorityLevel::LOW); +BENCHMARK(WalletCreateEncrypted, benchmark::PriorityLevel::LOW); +#endif + +} // namespace wallet |