|
4 | 4 |
|
5 | 5 | #include <bench/bench.h> |
6 | 6 |
|
| 7 | +#include <clientversion.h> |
7 | 8 | #include <crypto/sha256.h> |
8 | 9 | #include <util/strencodings.h> |
9 | 10 | #include <util/system.h> |
10 | 11 |
|
11 | | -#include <memory> |
| 12 | +#include <chrono> |
| 13 | +#include <cstdint> |
| 14 | +#include <iostream> |
| 15 | +#include <sstream> |
| 16 | +#include <vector> |
12 | 17 |
|
13 | 18 | static const char* DEFAULT_BENCH_FILTER = ".*"; |
| 19 | +static constexpr int64_t DEFAULT_MIN_TIME_MS{10}; |
14 | 20 |
|
15 | 21 | static void SetupBenchArgs(ArgsManager& argsman) |
16 | 22 | { |
17 | 23 | SetupHelpOptions(argsman); |
18 | 24 |
|
19 | | - 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); |
| 25 | + 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); |
20 | 26 | argsman.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
21 | | - argsman.AddArg("-list", "List benchmarks without executing them", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
| 27 | + argsman.AddArg("-list", "List benchmarks without executing them", ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS); |
| 28 | + argsman.AddArg("-min_time=<milliseconds>", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_INT, OptionsCategory::OPTIONS); |
22 | 29 | argsman.AddArg("-output_csv=<output.csv>", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
23 | 30 | argsman.AddArg("-output_json=<output.json>", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
24 | 31 | } |
@@ -48,17 +55,62 @@ int main(int argc, char** argv) |
48 | 55 | } |
49 | 56 |
|
50 | 57 | if (HelpRequested(argsman)) { |
51 | | - std::cout << argsman.GetHelpMessage(); |
| 58 | + std::cout << "Usage: bench_bitcoin [options]\n" |
| 59 | + "\n" |
| 60 | + << argsman.GetHelpMessage() |
| 61 | + << "Description:\n" |
| 62 | + "\n" |
| 63 | + " bench_bitcoin executes microbenchmarks. The quality of the benchmark results\n" |
| 64 | + " highly depend on the stability of the machine. It can sometimes be difficult\n" |
| 65 | + " to get stable, repeatable results, so here are a few tips:\n" |
| 66 | + "\n" |
| 67 | + " * Use pyperf [1] to disable frequency scaling, turbo boost etc. For best\n" |
| 68 | + " results, use CPU pinning and CPU isolation (see [2]).\n" |
| 69 | + "\n" |
| 70 | + " * Each call of run() should do exactly the same work. E.g. inserting into\n" |
| 71 | + " a std::vector doesn't do that as it will reallocate on certain calls. Make\n" |
| 72 | + " sure each run has exactly the same preconditions.\n" |
| 73 | + "\n" |
| 74 | + " * If results are still not reliable, increase runtime with e.g.\n" |
| 75 | + " -min_time=5000 to let a benchmark run for at least 5 seconds.\n" |
| 76 | + "\n" |
| 77 | + " * bench_bitcoin uses nanobench [3] for which there is extensive\n" |
| 78 | + " documentation available online.\n" |
| 79 | + "\n" |
| 80 | + "Environment Variables:\n" |
| 81 | + "\n" |
| 82 | + " To attach a profiler you can run a benchmark in endless mode. This can be\n" |
| 83 | + " done with the environment variable NANOBENCH_ENDLESS. E.g. like so:\n" |
| 84 | + "\n" |
| 85 | + " NANOBENCH_ENDLESS=MuHash ./bench_bitcoin -filter=MuHash\n" |
| 86 | + "\n" |
| 87 | + " In rare cases it can be useful to suppress stability warnings. This can be\n" |
| 88 | + " done with the environment variable NANOBENCH_SUPPRESS_WARNINGS, e.g:\n" |
| 89 | + "\n" |
| 90 | + " NANOBENCH_SUPPRESS_WARNINGS=1 ./bench_bitcoin\n" |
| 91 | + "\n" |
| 92 | + "Notes:\n" |
| 93 | + "\n" |
| 94 | + " 1. pyperf\n" |
| 95 | + " https://github.com/psf/pyperf\n" |
| 96 | + "\n" |
| 97 | + " 2. CPU pinning & isolation\n" |
| 98 | + " https://pyperf.readthedocs.io/en/latest/system.html\n" |
| 99 | + "\n" |
| 100 | + " 3. nanobench\n" |
| 101 | + " https://github.com/martinus/nanobench\n" |
| 102 | + "\n"; |
52 | 103 |
|
53 | 104 | return EXIT_SUCCESS; |
54 | 105 | } |
55 | 106 |
|
56 | 107 | benchmark::Args args; |
57 | | - args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); |
58 | | - args.is_list_only = argsman.GetBoolArg("-list", false); |
59 | 108 | args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", "")); |
| 109 | + args.is_list_only = argsman.GetBoolArg("-list", false); |
| 110 | + args.min_time = std::chrono::milliseconds(argsman.GetArg("-min_time", DEFAULT_MIN_TIME_MS)); |
60 | 111 | args.output_csv = argsman.GetArg("-output_csv", ""); |
61 | 112 | args.output_json = argsman.GetArg("-output_json", ""); |
| 113 | + args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); |
62 | 114 |
|
63 | 115 | benchmark::BenchRunner::RunAll(args); |
64 | 116 |
|
|
0 commit comments