|
| 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