bench: Add `--sanity-check` flag, use it in `make check` #25107

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2022-05-bench-one-iteration changing 4 files +19 −9
  1. laanwj commented at 2:33 PM on May 11, 2022: member

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

  2. laanwj added the label Tests on May 11, 2022
  3. theStack commented at 2:38 PM on May 11, 2022: member

    Concept ACK

  4. in src/bench/bench.cpp:74 in 28988ddb17 outdated
      68 | @@ -69,6 +69,13 @@ void benchmark::BenchRunner::RunAll(const Args& args)
      69 |          }
      70 |  
      71 |          Bench bench;
      72 | +        if (args.one_iteration) {
      73 | +            ankerl::nanobench::Config config;
      74 | +            config.mNumEpochs = 1;
    


    laanwj commented at 2:43 PM on May 11, 2022:

    Could also add separate flags for --num-epochs and --epoch-iterations (which default to 11 and 0 respectively, as they do currently in Config).


    martinus commented at 5:43 AM on May 12, 2022:

    I'd use bench.epochs(1).epochIterations(1) instead of modifying the Config members directly


    laanwj commented at 6:29 AM on May 12, 2022:

    That's a great suggestion, will do (edit: done).

  5. w0xlt commented at 2:46 PM on May 11, 2022: contributor

    Concept ACK

  6. laanwj force-pushed on May 12, 2022
  7. laanwj force-pushed on May 12, 2022
  8. in src/Makefile.test.include:367 in 63068c7525 outdated
     363 | @@ -364,8 +364,8 @@ endif
     364 |  if TARGET_WINDOWS
     365 |  else
     366 |  if ENABLE_BENCH
     367 | -	@echo "Running bench/bench_bitcoin ..."
     368 | -	$(BENCH_BINARY) > /dev/null
     369 | +	@echo "Running bench/bench_bitcoin (one iteration sanity check)..."
    


    laanwj commented at 6:33 AM on May 12, 2022:

    Also added a comment to preempt "why are we running the benchmarks in make check at all" questions.

  9. fanquake commented at 8:09 AM on May 12, 2022: member

    Concept ACK

  10. in src/bench/bench_bitcoin.cpp:32 in 63068c7525 outdated
      28 | @@ -29,6 +29,7 @@ static void SetupBenchArgs(ArgsManager& argsman)
      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("-one-iteration", "Run benchmarks for only one iteration (for testing purposes)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
    


    jonatack commented at 10:41 AM on May 12, 2022:

    nit, sort here and below


    jonatack commented at 11:06 AM on May 12, 2022:

    The other args are snakecased and this is kebabcase; maybe good to use one style or the other.


    laanwj commented at 11:08 AM on May 12, 2022:

    Yes, I agree. I'll convert all the arguments to kebab-case (which is customary for UNIX-style arguments) in another commit.

  11. in src/bench/bench.h:51 in 63068c7525 outdated
      47 | @@ -48,6 +48,7 @@ struct Args {
      48 |      fs::path output_csv;
      49 |      fs::path output_json;
      50 |      std::string regex_filter;
      51 | +    bool one_iteration;
    


    jonatack commented at 10:42 AM on May 12, 2022:

    nit, place/pack this just below the first bool member


    laanwj commented at 11:10 AM on May 12, 2022:

    ok, sure, why not, sorting the fields by type makes as much sense as anything


    jonatack commented at 11:11 AM on May 12, 2022:

    yes, they've been sorted roughly by increasing size

  12. jonatack commented at 10:42 AM on May 12, 2022: member

    Concept and approach ACK, now building and testing.

  13. laanwj force-pushed on May 12, 2022
  14. laanwj commented at 11:14 AM on May 12, 2022: member

    Re-pushed to address @jonatack's comments.

  15. in src/bench/bench.cpp:78 in c52a71ea05 outdated
      68 | @@ -69,6 +69,9 @@ void benchmark::BenchRunner::RunAll(const Args& args)
      69 |          }
      70 |  
      71 |          Bench bench;
      72 | +        if (args.one_iteration) {
      73 | +            bench.epochs(1).epochIterations(1);
      74 | +        }
    


    jonatack commented at 12:23 PM on May 12, 2022:

    maybe provide some kind of user feedback that the option is running (I did this to sanity-check that it was)

    --- a/src/bench/bench.cpp
    +++ b/src/bench/bench.cpp
    @@ -58,6 +58,9 @@ void benchmark::BenchRunner::RunAll(const Args& args)
         std::smatch baseMatch;
     
         std::vector<ankerl::nanobench::Result> benchmarkResults;
    +    if (args.one_iteration) {
    +        std::cout << "Running with --one-iteration option, i.e. epochs(1).epochIterations(1)" << std::endl;
    +    }
         for (const auto& p : benchmarks()) {
             if (!std::regex_match(p.first, baseMatch, reFilter)) {
    

    output

    $ time ./src/bench/bench_bitcoin -filter=WalletBalance*.* --one-iteration
    Running with --one-iteration option, i.e. epochs(1).epochIterations(1)
    Warning, results might be unstable:
    * DEBUG defined
    * CPU frequency scaling enabled: CPU 0 between 2,485.0 and 3,100.0 MHz
    * Turbo is enabled, CPU frequency will fluctuate
    
    Recommendations
    * Make sure you compile for Release
    * Use 'pyperf system tune' before benchmarking. See https://github.com/psf/pyperf
    
    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    

    (unrelated, and not sure there is a use case, but --one-iteration could later be changed to an integer --iterations arg)


    sipa commented at 6:01 PM on May 12, 2022:

    Revealing the fact that it's using epochs(1).epochIterations(1) seems like an unnecessary implementation detail for the bench_bitcoin user.


    martinus commented at 6:17 AM on May 13, 2022:

    I'd also prefer a config name like --sanity-check. Maybe in future this could do more to be quicker, like run all the benchmarks in parallel (I had a quick look if that works but got a segfault, probably due to some global states)


    laanwj commented at 8:36 AM on May 13, 2022:

    Revealing the fact that it's using epochs(1).epochIterations(1) seems like an unnecessary implementation detail for the bench_bitcoin user.

    Yeah. That's too much detail. But adding a warning message that it's active to the output makes sense, I guess.

    I'd also prefer a config name like --sanity-check. Maybe in future this could do more to be quicker, like run all the benchmarks in parallel (I had a quick look if that works but got a segfault, probably due to some global states)

    Agree on the rename. Running the benchmarks in parallel would be another stress test but it seems we're not ready for that :smile:

    Though ideally I would like to aim for <10ms per iteration for all benchmarks, so running 1 iteration in parallel shouldn't have that much effect. Running 1 of everything in serial is still supposed to be fast!


    fanquake commented at 1:18 PM on May 16, 2022:

    Agree on the rename. @laanwj did you want to do that rename here? If not, I'd like to merge this soon.


    laanwj commented at 9:06 AM on May 17, 2022:

    Yes, I'm going to make the requested changes here and re-push in a bit.

  16. jonatack commented at 12:26 PM on May 12, 2022: member

    Tested ACK c52a71ea05c787143124b1089ef4c895f8fb01bf though the reduction in run time isn't large in my testing

    OK
    Running bench/bench_bitcoin (one iteration sanity check)...
    bench/bench_bitcoin --one-iteration > /dev/null
    

    Modulo typo in first commit message s/kebab-hase/kebab-case/

  17. MarcoFalke commented at 5:44 AM on May 13, 2022: member

    Looks like #24924 might be related

  18. laanwj force-pushed on May 17, 2022
  19. laanwj commented at 9:30 AM on May 17, 2022: member

    Re-pushed:

    • Argument is now -sanity-check.
    • Add warning that results are useless.
    • Fix typo in commit message.

    Should be ready for final review round and merge.

  20. laanwj renamed this:
    bench: Add `--one-iteration` flag, use it in `make check`
    bench: Add `--sanity-check` flag, use it in `make check`
    on May 17, 2022
  21. bench: Add `--sanity-check` flag, use it in `make check`
    The benchmarks are run as part of `make check` for a minimum 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.
    652b54e532
  22. bench: Make all arguments -kebab-case
    This is customary for UNIX-style arguments, and more consistent with our
    other tools
    4f31c21b7f
  23. laanwj force-pushed on May 17, 2022
  24. hebasto commented at 9:57 AM on May 17, 2022: member

    Concept ACK.

  25. in src/bench/bench.cpp:61 in 4f31c21b7f
      56 | @@ -57,6 +57,10 @@ void benchmark::BenchRunner::RunAll(const Args& args)
      57 |      std::regex reFilter(args.regex_filter);
      58 |      std::smatch baseMatch;
      59 |  
      60 | +    if (args.sanity_check) {
      61 | +        std::cout << "Running with --sanity check option, benchmark results will be useless." << std::endl;
    


    hebasto commented at 10:28 AM on May 17, 2022:
            std::cout << "Running with -sanity-check option, benchmark results will be useless." << std::endl;
    

    Also s/--sanity-check/-sanity-check/ in the commit message?


    jonatack commented at 11:05 AM on May 17, 2022:

    I'm not sure as there isn't a single-letter option like -s here, but per https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html: "Long options consist of -- followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique."

    Edit: never mind, our convention is to use a single-hyphen prefix. That said, either way works for documentation purposes.

  26. in src/Makefile.test.include:368 in 4f31c21b7f
     363 | @@ -364,8 +364,8 @@ endif
     364 |  if TARGET_WINDOWS
     365 |  else
     366 |  if ENABLE_BENCH
     367 | -	@echo "Running bench/bench_bitcoin ..."
     368 | -	$(BENCH_BINARY) > /dev/null
     369 | +	@echo "Running bench/bench_bitcoin (one iteration sanity check)..."
     370 | +	$(BENCH_BINARY) --sanity-check > /dev/null
    


    hebasto commented at 10:29 AM on May 17, 2022:
    	$(BENCH_BINARY) -sanity-check > /dev/null
    
  27. jonatack commented at 11:15 AM on May 17, 2022: member

    ACK 4f31c21b7f384e50e0af8275e831085d1d69b386 on the sanity-check version per git diff c52a71e 4f31c28 (modulo s/--sanity check/--sanity-check/ in src/bench/bench.cpp::L61)

  28. laanwj commented at 11:56 AM on May 17, 2022: member

    @hebasto Maybe I'm an old UNIX fart in some things but I prefer long options prefixed with two -, I prefer not to change this. And you can specify them with one - if you want, sure, that works too.

  29. hebasto approved
  30. hebasto commented at 12:01 PM on May 17, 2022: member

    ACK 4f31c21b7f384e50e0af8275e831085d1d69b386, tested on Ubuntu 22.04.

  31. fanquake merged this on May 17, 2022
  32. fanquake closed this on May 17, 2022

  33. sidhujag referenced this in commit b08a8d310a on May 28, 2022
  34. MarcoFalke referenced this in commit 3baa0f5a60 on Oct 3, 2022
  35. DrahtBot locked this on May 17, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me