you need to set epochIterations=1 since the setup is only run once per epoch
Yes, I will add a new PR to make sure this is asserted in the new setup and explained in the error.
Nanobench has two iterations for better signal-to-noise ratio (framework cost vs measured code).
But if we apply a setup phase, we admit that the benchmark is heavy and the framework won't overshadow the actual measurement (e.g. compared to the cost of an i++, running a lambda can be costly). That's not the case here, so we disable epoch iterations and only leave the 11 default epochs for stability.
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index eab3f13d86..75022ee4db 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -53,9 +53,8 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
auto bal = GetBalance(wallet); // Cache
- bench.setup([&] {
- if (set_dirty) wallet.MarkDirty();
- })
+ bench.epochIterations(1)
+ .setup([&] { if (set_dirty) wallet.MarkDirty(); })
.run([&] {
bal = GetBalance(wallet);
if (add_mine) assert(bal.m_mine_trusted > 0);
diff --git a/src/bench/wallet_create.cpp b/src/bench/wallet_create.cpp
index 990bfdf006..615bb049dc 100644
--- a/src/bench/wallet_create.cpp
+++ b/src/bench/wallet_create.cpp
@@ -48,7 +48,8 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
const auto wallet_name = fs::PathToString(wallet_path);
std::shared_ptr<CWallet> wallet;
- bench.setup([&] {
+ bench.epochIterations(1)
+ .setup([&] {
if (wallet) {
// Release wallet
RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
diff --git a/src/bench/wallet_encrypt.cpp b/src/bench/wallet_encrypt.cpp
index e1ffc18a01..971a7797c8 100644
--- a/src/bench/wallet_encrypt.cpp
+++ b/src/bench/wallet_encrypt.cpp
@@ -37,7 +37,8 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)
std::unique_ptr<WalletDatabase> database;
std::shared_ptr<CWallet> wallet;
- bench.batch(key_count).unit("key").setup([&] {
+ bench.batch(key_count).unit("key").epochIterations(1)
+ .setup([&] {
if (wallet) {
TestUnloadWallet(std::move(wallet));
}
@@ -63,7 +64,6 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)
for (const auto& [_, key] : wallet->mapMasterKeys){
assert(key.nDeriveIterations == CMasterKey::DEFAULT_DERIVE_ITERATIONS);
}
-
});
}
diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp
index 0ac6006ec1..f7d9012caf 100644
--- a/src/bench/wallet_loading.cpp
+++ b/src/bench/wallet_loading.cpp
@@ -58,7 +58,8 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench)
options.require_create = false;
options.require_existing = true;
- bench.epochs(5).setup([&] {
+ bench.epochs(5).epochIterations(1)
+ .setup([&] {
TestUnloadWallet(std::move(wallet));
database = MakeWalletDatabase("", options, status, error);
})