Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

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

Commit
eed4ae86ad38b2d04670e44a941bd96129906f4c
Author
Phil Nash ·
Parents
df5c31bb1938

Files · Download .tar.gz

Changes

 include/internal/catch_benchmark.cpp       | 6 +++++-
 include/internal/catch_benchmark.h         | 6 ++++--
 include/internal/catch_commandline.cpp     | 3 +++
 include/internal/catch_config.cpp          | 1 +
 include/internal/catch_config.hpp          | 2 ++
 include/internal/catch_interfaces_config.h | 1 +
 6 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/internal/catch_benchmark.cpp b/include/internal/catch_benchmark.cpp
index 51a844f6..d92b255c 100644
--- a/include/internal/catch_benchmark.cpp
+++ b/include/internal/catch_benchmark.cpp
@@ -12,7 +12,11 @@
 
 namespace Catch {
 
-    void BenchmarkLooper::reportStart() const {
+    auto BenchmarkLooper::getResolution() -> uint64_t {
+        return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple();
+    }
+
+    void BenchmarkLooper::reportStart() {
         getResultCapture().benchmarkStarting( { m_name } );
     }
     auto BenchmarkLooper::needsMoreIterations() -> bool {
diff --git a/include/internal/catch_benchmark.h b/include/internal/catch_benchmark.h
index 7b01507a..ffb1db78 100644
--- a/include/internal/catch_benchmark.h
+++ b/include/internal/catch_benchmark.h
@@ -23,11 +23,13 @@ namespace Catch {
         size_t m_iterationsToRun = 1;
         uint64_t m_resolution;
         Timer m_timer;
+
+        static auto getResolution() -> uint64_t;
     public:
         // Keep most of this inline as it's on the code path that is being timed
         BenchmarkLooper( StringRef name )
         :   m_name( name.c_str() ),
-            m_resolution( getEstimatedClockResolution()*10 )
+            m_resolution( getResolution() )
         {
             reportStart();
             m_timer.start();
@@ -43,7 +45,7 @@ namespace Catch {
             ++m_count;
         }
 
-        void reportStart() const;
+        void reportStart();
         auto needsMoreIterations() -> bool;
     };
 
diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp
index b94bc2d2..7342ac42 100644
--- a/include/internal/catch_commandline.cpp
+++ b/include/internal/catch_commandline.cpp
@@ -153,6 +153,9 @@ namespace Catch {
             + Opt( setColourUsage, "yes|no" )
                 ["--use-colour"]
                 ( "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" )
                 ( "which test or tests to use" );
diff --git a/include/internal/catch_config.cpp b/include/internal/catch_config.cpp
index ae1e95dd..d88a3d14 100644
--- a/include/internal/catch_config.cpp
+++ b/include/internal/catch_config.cpp
@@ -49,6 +49,7 @@ namespace Catch {
     ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
     RunTests::InWhatOrder Config::runOrder() const     { return m_data.runOrder; }
     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; }
     bool Config::shouldDebugBreak() const              { return m_data.shouldDebugBreak; }
     int Config::abortAfter() const                     { return m_data.abortAfter; }
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 531543c2..6bf792b0 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -38,6 +38,7 @@ namespace Catch {
 
         int abortAfter = -1;
         unsigned int rngSeed = 0;
+        int benchmarkResolutionMultiple = 10;
 
         Verbosity verbosity = Verbosity::Normal;
         WarnAbout::What warnings = WarnAbout::Nothing;
@@ -88,6 +89,7 @@ namespace Catch {
         ShowDurations::OrNot showDurations() const override;
         RunTests::InWhatOrder runOrder() const override;
         unsigned int rngSeed() const override;
+        int benchmarkResolutionMultiple() const override;
         UseColour::YesOrNo useColour() const override;
         bool shouldDebugBreak() const override;
         int abortAfter() const override;
diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h
index d2d7602c..436b80eb 100644
--- a/include/internal/catch_interfaces_config.h
+++ b/include/internal/catch_interfaces_config.h
@@ -62,6 +62,7 @@ namespace Catch {
         virtual TestSpec const& testSpec() const = 0;
         virtual RunTests::InWhatOrder runOrder() const = 0;
         virtual unsigned int rngSeed() const = 0;
+        virtual int benchmarkResolutionMultiple() const = 0;
         virtual UseColour::YesOrNo useColour() const = 0;
         virtual std::vector<std::string> const& getSectionsToRun() const = 0;
         virtual Verbosity verbosity() const = 0;