bench: Utilize setup() for WalletLoading and use a real database

Instead of making a mock database and duplicating it for the benchmark,
use a real database. Also use setup() to avoid measuring the overhead in
the benchmark.
This commit is contained in:
Ava Chow
2026-04-06 14:58:53 -07:00
parent 9a7604fd25
commit 57820c472b

View File

@@ -42,7 +42,12 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench)
// Setup the wallet
// Loading the wallet will also create it
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
auto database = CreateMockableWalletDatabase();
DatabaseStatus status;
DatabaseOptions options;
options.require_format = DatabaseFormat::SQLITE;
options.require_create = true;
bilingual_str error;
auto database = MakeWalletDatabase("", options, status, error);
auto wallet = TestCreateWallet(std::move(database), context, create_flags);
// Generate a bunch of transactions and addresses to put into the wallet
@@ -50,18 +55,20 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench)
AddTx(*wallet);
}
database = DuplicateMockDatabase(wallet->GetDatabase());
options.require_create = false;
options.require_existing = true;
// reload the wallet for the actual benchmark
bench.epochs(5)
.setup([&] {
TestUnloadWallet(std::move(wallet));
database = MakeWalletDatabase("", options, status, error);
})
.run([&] {
wallet = TestLoadWallet(std::move(database), context);
});
// Cleanup
TestUnloadWallet(std::move(wallet));
bench.epochs(5).run([&] {
wallet = TestLoadWallet(std::move(database), context);
// Cleanup
database = DuplicateMockDatabase(wallet->GetDatabase());
TestUnloadWallet(std::move(wallet));
});
}
BENCHMARK(WalletLoadingDescriptors);