2021-06-26 12:03:16 +02:00
// Copyright (c) 2015-2020 The Bitcoin Core developers
Simple benchmarking framework
Benchmarking framework, loosely based on google's micro-benchmarking
library (https://github.com/google/benchmark)
Wny not use the Google Benchmark framework? Because adding Even More Dependencies
isn't worth it. If we get a dozen or three benchmarks and need nanosecond-accurate
timings of threaded code then switching to the full-blown Google Benchmark library
should be considered.
The benchmark framework is hard-coded to run each benchmark for one wall-clock second,
and then spits out .csv-format timing information to stdout. It is left as an
exercise for later (or maybe never) to add command-line arguments to specify which
benchmark(s) to run, how long to run them for, how to format results, etc etc etc.
Again, see the Google Benchmark framework for where that might end up.
See src/bench/MilliSleep.cpp for a sanity-test benchmark that just benchmarks
'sleep 100 milliseconds.'
To compile and run benchmarks:
cd src; make bench
Sample output:
Benchmark,count,min,max,average
Sleep100ms,10,0.101854,0.105059,0.103881
2015-09-24 19:13:38 +02:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2020-03-19 23:46:56 +01:00
# include <bench/bench.h>
Simple benchmarking framework
Benchmarking framework, loosely based on google's micro-benchmarking
library (https://github.com/google/benchmark)
Wny not use the Google Benchmark framework? Because adding Even More Dependencies
isn't worth it. If we get a dozen or three benchmarks and need nanosecond-accurate
timings of threaded code then switching to the full-blown Google Benchmark library
should be considered.
The benchmark framework is hard-coded to run each benchmark for one wall-clock second,
and then spits out .csv-format timing information to stdout. It is left as an
exercise for later (or maybe never) to add command-line arguments to specify which
benchmark(s) to run, how long to run them for, how to format results, etc etc etc.
Again, see the Google Benchmark framework for where that might end up.
See src/bench/MilliSleep.cpp for a sanity-test benchmark that just benchmarks
'sleep 100 milliseconds.'
To compile and run benchmarks:
cd src; make bench
Sample output:
Benchmark,count,min,max,average
Sleep100ms,10,0.101854,0.105059,0.103881
2015-09-24 19:13:38 +02:00
2020-03-19 23:46:56 +01:00
# include <crypto/sha256.h>
# include <stacktraces.h>
2018-06-04 08:44:07 +02:00
# include <util/strencodings.h>
2021-06-27 08:33:13 +02:00
# include <util/system.h>
2020-07-20 17:03:57 +02:00
2020-03-19 23:46:56 +01:00
# include <bls/bls.h>
2018-05-24 13:56:49 +02:00
2020-07-20 17:03:57 +02:00
static const char * DEFAULT_BENCH_FILTER = " .* " ;
2022-05-21 10:00:37 +02:00
static void SetupBenchArgs ( ArgsManager & argsman )
2021-03-19 16:00:24 +01:00
{
2022-05-21 11:30:27 +02:00
SetupHelpOptions ( argsman ) ;
2022-05-21 10:12:13 +02:00
2022-05-21 10:00:37 +02:00
argsman . AddArg ( " -list " , " List benchmarks without executing them " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -filter=<regex> " , strprintf ( " Regular expression filter to select benchmark by name (default: %s) " , DEFAULT_BENCH_FILTER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -asymptote=n1,n2,n3,... " , strprintf ( " Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark " ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -output_csv=<output.csv> " , " Generate CSV file with the most important benchmark results. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -output_json=<output.json> " , " Generate JSON file with all benchmark results. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-03-19 16:00:24 +01:00
}
2021-06-26 12:03:16 +02:00
// parses a comma separated list like "10,20,30,50"
static std : : vector < double > parseAsymptote ( const std : : string & str ) {
std : : stringstream ss ( str ) ;
std : : vector < double > numbers ;
double d ;
char c ;
while ( ss > > d ) {
numbers . push_back ( d ) ;
ss > > c ;
}
return numbers ;
}
2018-07-17 14:04:33 +02:00
int main ( int argc , char * * argv )
Simple benchmarking framework
Benchmarking framework, loosely based on google's micro-benchmarking
library (https://github.com/google/benchmark)
Wny not use the Google Benchmark framework? Because adding Even More Dependencies
isn't worth it. If we get a dozen or three benchmarks and need nanosecond-accurate
timings of threaded code then switching to the full-blown Google Benchmark library
should be considered.
The benchmark framework is hard-coded to run each benchmark for one wall-clock second,
and then spits out .csv-format timing information to stdout. It is left as an
exercise for later (or maybe never) to add command-line arguments to specify which
benchmark(s) to run, how long to run them for, how to format results, etc etc etc.
Again, see the Google Benchmark framework for where that might end up.
See src/bench/MilliSleep.cpp for a sanity-test benchmark that just benchmarks
'sleep 100 milliseconds.'
To compile and run benchmarks:
cd src; make bench
Sample output:
Benchmark,count,min,max,average
Sleep100ms,10,0.101854,0.105059,0.103881
2015-09-24 19:13:38 +02:00
{
2022-05-21 10:00:37 +02:00
ArgsManager argsman ;
SetupBenchArgs ( argsman ) ;
2018-05-30 19:42:58 +02:00
std : : string error ;
2022-05-21 10:00:37 +02:00
if ( ! argsman . ParseParameters ( argc , argv , error ) ) {
2022-03-21 18:28:10 +01:00
tfm : : format ( std : : cerr , " Error parsing command line arguments: %s \n " , error ) ;
2018-05-31 11:14:07 +02:00
return EXIT_FAILURE ;
2018-05-30 19:42:58 +02:00
}
2020-07-20 17:03:57 +02:00
2022-05-21 10:00:37 +02:00
if ( HelpRequested ( argsman ) ) {
std : : cout < < argsman . GetHelpMessage ( ) ;
2018-05-31 11:14:07 +02:00
return EXIT_SUCCESS ;
2020-07-20 17:03:57 +02:00
}
2021-06-26 12:03:16 +02:00
benchmark : : Args args ;
2022-05-21 10:00:37 +02:00
args . regex_filter = argsman . GetArg ( " -filter " , DEFAULT_BENCH_FILTER ) ;
args . is_list_only = argsman . GetBoolArg ( " -list " , false ) ;
args . asymptote = parseAsymptote ( argsman . GetArg ( " -asymptote " , " " ) ) ;
args . output_csv = argsman . GetArg ( " -output_csv " , " " ) ;
args . output_json = argsman . GetArg ( " -output_json " , " " ) ;
2022-05-29 21:49:04 +02:00
2021-06-26 12:03:16 +02:00
benchmark : : BenchRunner : : RunAll ( args ) ;
Simple benchmarking framework
Benchmarking framework, loosely based on google's micro-benchmarking
library (https://github.com/google/benchmark)
Wny not use the Google Benchmark framework? Because adding Even More Dependencies
isn't worth it. If we get a dozen or three benchmarks and need nanosecond-accurate
timings of threaded code then switching to the full-blown Google Benchmark library
should be considered.
The benchmark framework is hard-coded to run each benchmark for one wall-clock second,
and then spits out .csv-format timing information to stdout. It is left as an
exercise for later (or maybe never) to add command-line arguments to specify which
benchmark(s) to run, how long to run them for, how to format results, etc etc etc.
Again, see the Google Benchmark framework for where that might end up.
See src/bench/MilliSleep.cpp for a sanity-test benchmark that just benchmarks
'sleep 100 milliseconds.'
To compile and run benchmarks:
cd src; make bench
Sample output:
Benchmark,count,min,max,average
Sleep100ms,10,0.101854,0.105059,0.103881
2015-09-24 19:13:38 +02:00
2018-05-31 11:14:07 +02:00
return EXIT_SUCCESS ;
Simple benchmarking framework
Benchmarking framework, loosely based on google's micro-benchmarking
library (https://github.com/google/benchmark)
Wny not use the Google Benchmark framework? Because adding Even More Dependencies
isn't worth it. If we get a dozen or three benchmarks and need nanosecond-accurate
timings of threaded code then switching to the full-blown Google Benchmark library
should be considered.
The benchmark framework is hard-coded to run each benchmark for one wall-clock second,
and then spits out .csv-format timing information to stdout. It is left as an
exercise for later (or maybe never) to add command-line arguments to specify which
benchmark(s) to run, how long to run them for, how to format results, etc etc etc.
Again, see the Google Benchmark framework for where that might end up.
See src/bench/MilliSleep.cpp for a sanity-test benchmark that just benchmarks
'sleep 100 milliseconds.'
To compile and run benchmarks:
cd src; make bench
Sample output:
Benchmark,count,min,max,average
Sleep100ms,10,0.101854,0.105059,0.103881
2015-09-24 19:13:38 +02:00
}