Skip to content

Commit dd8a2df

Browse files
committed
Merge bitcoin/bitcoin#25107: bench: Add --sanity-check flag, use it in make check
4f31c21 bench: Make all arguments -kebab-case (laanwj) 652b54e bench: Add `--sanity-check` flag, use it in `make check` (laanwj) Pull request description: The benchmarks are run as part of `make check` for a crash-sanity check. The actual results are being ignored. So only run them for one iteration. This makes the `bench_bitcoin` part take 2m00 instead of 5m20 here. Which is still too long (imo), but this needs to be solved in the `WalletLoading*` benchmarks which take that long per iteration. Also change all `bench_bitcoin` arguments to kebab-case to be consistent with the other tools (in a separate commit). ACKs for top commit: jonatack: ACK 4f31c21 on the sanity-check version per `git diff c52a71e 4f31c28` (modulo s/--sanity check/--sanity-check/ in src/bench/bench.cpp::L61) hebasto: ACK 4f31c21, tested on Ubuntu 22.04. Tree-SHA512: 2661d130fd82e57c9041755190997a4af588fadddcdd05e04fd024f75da1202480e9feab5764566e8dfe7930e8ae0ec71e93f40ac373274953d274072723980d
2 parents 1ab389b + 4f31c21 commit dd8a2df

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/Makefile.test.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ endif
364364
if TARGET_WINDOWS
365365
else
366366
if ENABLE_BENCH
367-
@echo "Running bench/bench_bitcoin ..."
368-
$(BENCH_BINARY) > /dev/null
367+
@echo "Running bench/bench_bitcoin (one iteration sanity check)..."
368+
$(BENCH_BINARY) --sanity-check > /dev/null
369369
endif
370370
endif
371371
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check

src/bench/bench.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void benchmark::BenchRunner::RunAll(const Args& args)
5757
std::regex reFilter(args.regex_filter);
5858
std::smatch baseMatch;
5959

60+
if (args.sanity_check) {
61+
std::cout << "Running with --sanity check option, benchmark results will be useless." << std::endl;
62+
}
63+
6064
std::vector<ankerl::nanobench::Result> benchmarkResults;
6165
for (const auto& p : benchmarks()) {
6266
if (!std::regex_match(p.first, baseMatch, reFilter)) {
@@ -69,6 +73,9 @@ void benchmark::BenchRunner::RunAll(const Args& args)
6973
}
7074

7175
Bench bench;
76+
if (args.sanity_check) {
77+
bench.epochs(1).epochIterations(1);
78+
}
7279
bench.name(p.first);
7380
if (args.min_time > 0ms) {
7481
// convert to nanos before dividing to reduce rounding errors

src/bench/bench.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef std::function<void(Bench&)> BenchFunction;
4343

4444
struct Args {
4545
bool is_list_only;
46+
bool sanity_check;
4647
std::chrono::milliseconds min_time;
4748
std::vector<double> asymptote;
4849
fs::path output_csv;

src/bench/bench_bitcoin.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ static void SetupBenchArgs(ArgsManager& argsman)
2626
argsman.AddArg("-asymptote=<n1,n2,n3,...>", "Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2727
argsman.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2828
argsman.AddArg("-list", "List benchmarks without executing them", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
29-
argsman.AddArg("-min_time=<milliseconds>", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
30-
argsman.AddArg("-output_csv=<output.csv>", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
31-
argsman.AddArg("-output_json=<output.json>", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
29+
argsman.AddArg("-min-time=<milliseconds>", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
30+
argsman.AddArg("-output-csv=<output.csv>", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
31+
argsman.AddArg("-output-json=<output.json>", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
32+
argsman.AddArg("-sanity-check", "Run benchmarks for only one iteration", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
3233
}
3334

3435
// parses a comma separated list like "10,20,30,50"
@@ -73,7 +74,7 @@ int main(int argc, char** argv)
7374
" sure each run has exactly the same preconditions.\n"
7475
"\n"
7576
" * If results are still not reliable, increase runtime with e.g.\n"
76-
" -min_time=5000 to let a benchmark run for at least 5 seconds.\n"
77+
" -min-time=5000 to let a benchmark run for at least 5 seconds.\n"
7778
"\n"
7879
" * bench_bitcoin uses nanobench [3] for which there is extensive\n"
7980
" documentation available online.\n"
@@ -108,10 +109,11 @@ int main(int argc, char** argv)
108109
benchmark::Args args;
109110
args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", ""));
110111
args.is_list_only = argsman.GetBoolArg("-list", false);
111-
args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min_time", DEFAULT_MIN_TIME_MS));
112-
args.output_csv = argsman.GetPathArg("-output_csv");
113-
args.output_json = argsman.GetPathArg("-output_json");
112+
args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min-time", DEFAULT_MIN_TIME_MS));
113+
args.output_csv = argsman.GetPathArg("-output-csv");
114+
args.output_json = argsman.GetPathArg("-output-json");
114115
args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER);
116+
args.sanity_check = argsman.GetBoolArg("-sanity-check", false);
115117

116118
benchmark::BenchRunner::RunAll(args);
117119

0 commit comments

Comments
 (0)