diff options
| author | Martin Hořeňovský | 2020-02-03 18:08:15 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-06 11:36:46 +0100 |
| commit | cd7d7a1c67f1b915d883fa7979cbd2162dde7d46 (patch) | |
| tree | 671c0f0cd2cae0273a91d2e7b8b2bac3ae1a9a8e /src/catch2/benchmark | |
| parent | 86e19b952dc4a4a2526037602abcc96a80607acc (diff) | |
| download | catch3-cd7d7a1c67f1b915d883fa7979cbd2162dde7d46.tar.gz | |
Remove CATCH_CONFIG_ENABLE_BENCHMARKING compilation toggle
Now that Catch2 is a proper library, we can always build the full
library (comparatively minor slowdown) and the user can avoid
including benchmarking headers to avoid the compilation slowdown.
Diffstat (limited to 'src/catch2/benchmark')
| -rw-r--r-- | src/catch2/benchmark/catch_chronometer.cpp | 14 | ||||
| -rw-r--r-- | src/catch2/benchmark/catch_chronometer.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/benchmark/catch_optimizer.hpp | 3 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_benchmark_function.cpp | 14 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_benchmark_function.hpp | 4 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_complete_invoke.cpp | 14 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_complete_invoke.hpp | 4 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_run_for_at_least.cpp | 29 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_run_for_at_least.hpp | 10 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_stats.cpp | 4 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_stats.hpp | 1 |
11 files changed, 85 insertions, 14 deletions
diff --git a/src/catch2/benchmark/catch_chronometer.cpp b/src/catch2/benchmark/catch_chronometer.cpp new file mode 100644 index 00000000..737c3e13 --- /dev/null +++ b/src/catch2/benchmark/catch_chronometer.cpp @@ -0,0 +1,14 @@ +/* + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#include <catch2/benchmark/catch_chronometer.hpp> + +namespace Catch { + namespace Benchmark { + namespace Detail { + ChronometerConcept::~ChronometerConcept() = default; + } // namespace Detail + } // namespace Benchmark +} // namespace Catch diff --git a/src/catch2/benchmark/catch_chronometer.hpp b/src/catch2/benchmark/catch_chronometer.hpp index 19a7ec05..e150d20d 100644 --- a/src/catch2/benchmark/catch_chronometer.hpp +++ b/src/catch2/benchmark/catch_chronometer.hpp @@ -22,7 +22,7 @@ namespace Catch { struct ChronometerConcept { virtual void start() = 0; virtual void finish() = 0; - virtual ~ChronometerConcept() = default; + virtual ~ChronometerConcept(); // = default; }; template <typename Clock> struct ChronometerModel final : public ChronometerConcept { diff --git a/src/catch2/benchmark/catch_optimizer.hpp b/src/catch2/benchmark/catch_optimizer.hpp index bda7c6d7..194530c6 100644 --- a/src/catch2/benchmark/catch_optimizer.hpp +++ b/src/catch2/benchmark/catch_optimizer.hpp @@ -15,6 +15,9 @@ # include <atomic> // atomic_thread_fence #endif +#include <type_traits> +#include <utility> + namespace Catch { namespace Benchmark { #if defined(__GNUC__) || defined(__clang__) diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.cpp b/src/catch2/benchmark/detail/catch_benchmark_function.cpp new file mode 100644 index 00000000..a2f3029e --- /dev/null +++ b/src/catch2/benchmark/detail/catch_benchmark_function.cpp @@ -0,0 +1,14 @@ +/* + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#include <catch2/benchmark/detail/catch_benchmark_function.hpp> + +namespace Catch { + namespace Benchmark { + namespace Detail { + BenchmarkFunction::callable::~callable() = default; + } // namespace Detail + } // namespace Benchmark +} // namespace Catch diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/src/catch2/benchmark/detail/catch_benchmark_function.hpp index e25ae220..4fd86896 100644 --- a/src/catch2/benchmark/detail/catch_benchmark_function.hpp +++ b/src/catch2/benchmark/detail/catch_benchmark_function.hpp @@ -1,4 +1,4 @@ - /* +/* * Created by Joachim on 16/04/2019. * Adapted from donated nonius code. * @@ -41,7 +41,7 @@ namespace Catch { struct callable { virtual void call(Chronometer meter) const = 0; virtual callable* clone() const = 0; - virtual ~callable() = default; + virtual ~callable(); // = default; }; template <typename Fun> struct model : public callable { diff --git a/src/catch2/benchmark/detail/catch_complete_invoke.cpp b/src/catch2/benchmark/detail/catch_complete_invoke.cpp new file mode 100644 index 00000000..c074f7a3 --- /dev/null +++ b/src/catch2/benchmark/detail/catch_complete_invoke.cpp @@ -0,0 +1,14 @@ +/* + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#include <catch2/benchmark/detail/catch_complete_invoke.hpp> + +namespace Catch { + namespace Benchmark { + namespace Detail { + const std::string benchmarkErrorMsg = "a benchmark failed to run successfully"; + } // namespace Detail + } // namespace Benchmark +} // namespace Catch diff --git a/src/catch2/benchmark/detail/catch_complete_invoke.hpp b/src/catch2/benchmark/detail/catch_complete_invoke.hpp index 8306cc0f..497e0b3f 100644 --- a/src/catch2/benchmark/detail/catch_complete_invoke.hpp +++ b/src/catch2/benchmark/detail/catch_complete_invoke.hpp @@ -12,6 +12,8 @@ #define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED #include <catch2/catch_enforce.h> +#include <catch2/catch_interfaces_capture.h> +#include <catch2/catch_interfaces_registry_hub.h> #include <type_traits> #include <utility> @@ -51,7 +53,7 @@ namespace Catch { return CompleteInvoker<ResultOf_t<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...); } - const std::string benchmarkErrorMsg = "a benchmark failed to run successfully"; + extern const std::string benchmarkErrorMsg; } // namespace Detail template <typename Fun> diff --git a/src/catch2/benchmark/detail/catch_run_for_at_least.cpp b/src/catch2/benchmark/detail/catch_run_for_at_least.cpp new file mode 100644 index 00000000..89c1e749 --- /dev/null +++ b/src/catch2/benchmark/detail/catch_run_for_at_least.cpp @@ -0,0 +1,29 @@ +/* + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +// Run a function for a minimum amount of time +#include <catch2/benchmark/detail/catch_run_for_at_least.hpp> + +#include <exception> +#include <catch2/catch_enforce.h> + +namespace Catch { + namespace Benchmark { + namespace Detail { + struct optimized_away_error : std::exception { + const char* what() const noexcept override; + }; + + const char* optimized_away_error::what() const noexcept { + return "could not measure benchmark, maybe it was optimized away"; + } + + void throw_optimized_away_error() { + Catch::throw_exception(optimized_away_error{}); + } + + } // namespace Detail + } // namespace Benchmark +} // namespace Catch diff --git a/src/catch2/benchmark/detail/catch_run_for_at_least.hpp b/src/catch2/benchmark/detail/catch_run_for_at_least.hpp index 24107c67..325e5227 100644 --- a/src/catch2/benchmark/detail/catch_run_for_at_least.hpp +++ b/src/catch2/benchmark/detail/catch_run_for_at_least.hpp @@ -39,11 +39,9 @@ namespace Catch { template <typename Clock, typename Fun> using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type; - struct optimized_away_error : std::exception { - const char* what() const noexcept override { - return "could not measure benchmark, maybe it was optimized away"; - } - }; + + [[noreturn]] + void throw_optimized_away_error(); template <typename Clock, typename Fun> TimingOf<Clock, Fun(run_for_at_least_argument_t<Clock, Fun>)> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) { @@ -56,7 +54,7 @@ namespace Catch { } iters *= 2; } - throw optimized_away_error{}; + throw_optimized_away_error(); } } // namespace Detail } // namespace Benchmark diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp index f82fb0b7..5aacce01 100644 --- a/src/catch2/benchmark/detail/catch_stats.cpp +++ b/src/catch2/benchmark/detail/catch_stats.cpp @@ -8,8 +8,6 @@ // Statistical analysis tools -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - #include <catch2/benchmark/detail/catch_stats.hpp> #include <catch2/catch_compiler_capabilities.h> @@ -220,5 +218,3 @@ namespace Catch { } // namespace Detail } // namespace Benchmark } // namespace Catch - -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp index 6fca2c49..2f27451f 100644 --- a/src/catch2/benchmark/detail/catch_stats.hpp +++ b/src/catch2/benchmark/detail/catch_stats.hpp @@ -23,6 +23,7 @@ #include <cmath> #include <utility> #include <cstddef> +#include <random> namespace Catch { namespace Benchmark { |