Added config to control multiple of clock resolution to run benchmark iterations for

This commit is contained in:
Phil Nash 2017-08-09 22:26:17 +01:00
parent df5c31bb19
commit eed4ae86ad
6 changed files with 16 additions and 3 deletions

View File

@ -12,7 +12,11 @@
namespace Catch { namespace Catch {
void BenchmarkLooper::reportStart() const { auto BenchmarkLooper::getResolution() -> uint64_t {
return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple();
}
void BenchmarkLooper::reportStart() {
getResultCapture().benchmarkStarting( { m_name } ); getResultCapture().benchmarkStarting( { m_name } );
} }
auto BenchmarkLooper::needsMoreIterations() -> bool { auto BenchmarkLooper::needsMoreIterations() -> bool {

View File

@ -23,11 +23,13 @@ namespace Catch {
size_t m_iterationsToRun = 1; size_t m_iterationsToRun = 1;
uint64_t m_resolution; uint64_t m_resolution;
Timer m_timer; Timer m_timer;
static auto getResolution() -> uint64_t;
public: public:
// Keep most of this inline as it's on the code path that is being timed // Keep most of this inline as it's on the code path that is being timed
BenchmarkLooper( StringRef name ) BenchmarkLooper( StringRef name )
: m_name( name.c_str() ), : m_name( name.c_str() ),
m_resolution( getEstimatedClockResolution()*10 ) m_resolution( getResolution() )
{ {
reportStart(); reportStart();
m_timer.start(); m_timer.start();
@ -43,7 +45,7 @@ namespace Catch {
++m_count; ++m_count;
} }
void reportStart() const; void reportStart();
auto needsMoreIterations() -> bool; auto needsMoreIterations() -> bool;
}; };

View File

@ -153,6 +153,9 @@ namespace Catch {
+ Opt( setColourUsage, "yes|no" ) + Opt( setColourUsage, "yes|no" )
["--use-colour"] ["--use-colour"]
( "should output be colourised" ) ( "should output be colourised" )
+ Opt( config.benchmarkResolutionMultiple, "multiplier" )
["--benchmark-resolution-multiple"]
( "multiple of clock resolution to run benchmarks" )
+ Arg( config.testsOrTags, "test name|pattern|tags" ) + Arg( config.testsOrTags, "test name|pattern|tags" )
( "which test or tests to use" ); ( "which test or tests to use" );

View File

@ -49,6 +49,7 @@ namespace Catch {
ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; }
unsigned int Config::rngSeed() const { return m_data.rngSeed; } unsigned int Config::rngSeed() const { return m_data.rngSeed; }
int Config::benchmarkResolutionMultiple() const { return m_data.benchmarkResolutionMultiple; }
UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } UseColour::YesOrNo Config::useColour() const { return m_data.useColour; }
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
int Config::abortAfter() const { return m_data.abortAfter; } int Config::abortAfter() const { return m_data.abortAfter; }

View File

@ -38,6 +38,7 @@ namespace Catch {
int abortAfter = -1; int abortAfter = -1;
unsigned int rngSeed = 0; unsigned int rngSeed = 0;
int benchmarkResolutionMultiple = 10;
Verbosity verbosity = Verbosity::Normal; Verbosity verbosity = Verbosity::Normal;
WarnAbout::What warnings = WarnAbout::Nothing; WarnAbout::What warnings = WarnAbout::Nothing;
@ -88,6 +89,7 @@ namespace Catch {
ShowDurations::OrNot showDurations() const override; ShowDurations::OrNot showDurations() const override;
RunTests::InWhatOrder runOrder() const override; RunTests::InWhatOrder runOrder() const override;
unsigned int rngSeed() const override; unsigned int rngSeed() const override;
int benchmarkResolutionMultiple() const override;
UseColour::YesOrNo useColour() const override; UseColour::YesOrNo useColour() const override;
bool shouldDebugBreak() const override; bool shouldDebugBreak() const override;
int abortAfter() const override; int abortAfter() const override;

View File

@ -62,6 +62,7 @@ namespace Catch {
virtual TestSpec const& testSpec() const = 0; virtual TestSpec const& testSpec() const = 0;
virtual RunTests::InWhatOrder runOrder() const = 0; virtual RunTests::InWhatOrder runOrder() const = 0;
virtual unsigned int rngSeed() const = 0; virtual unsigned int rngSeed() const = 0;
virtual int benchmarkResolutionMultiple() const = 0;
virtual UseColour::YesOrNo useColour() const = 0; virtual UseColour::YesOrNo useColour() const = 0;
virtual std::vector<std::string> const& getSectionsToRun() const = 0; virtual std::vector<std::string> const& getSectionsToRun() const = 0;
virtual Verbosity verbosity() const = 0; virtual Verbosity verbosity() const = 0;