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 | |
| 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.
38 files changed, 2377 insertions, 88 deletions
diff --git a/docs/benchmarks.md b/docs/benchmarks.md index 295bba30..6513cc2d 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -3,10 +3,6 @@ > [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0. -_Note that benchmarking support is disabled by default and to enable it, -you need to define `CATCH_CONFIG_ENABLE_BENCHMARKING`. For more details, -see the [compile-time configuration documentation](configuration.md#top)._ - Writing benchmarks is not easy. Catch simplifies certain aspects but you'll always need to take care about various aspects. Understanding a few things about the way Catch runs your code will be very helpful when writing your benchmarks. diff --git a/docs/configuration.md b/docs/configuration.md index 8dc80e95..f0dac1c9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -152,7 +152,6 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`. CATCH_CONFIG_DISABLE // Disables assertions and test case registration CATCH_CONFIG_WCHAR // Enables use of wchart_t CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr - CATCH_CONFIG_ENABLE_BENCHMARKING // Enables the integrated benchmarking features (has a significant effect on compilation speed) CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8c221b2..5ccdeb69 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,10 @@ set(BENCHMARK_HEADERS ${SOURCES_DIR}/benchmark/detail/catch_timing.hpp ) set(BENCHMARK_SOURCES + ${SOURCES_DIR}/benchmark/catch_chronometer.cpp + ${SOURCES_DIR}/benchmark/detail/catch_benchmark_function.cpp + ${SOURCES_DIR}/benchmark/detail/catch_complete_invoke.cpp + ${SOURCES_DIR}/benchmark/detail/catch_run_for_at_least.cpp ${SOURCES_DIR}/benchmark/detail/catch_stats.cpp ) 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 { diff --git a/src/catch2/catch.hpp b/src/catch2/catch.hpp index 3ecbdf69..9e2e690a 100644 --- a/src/catch2/catch.hpp +++ b/src/catch2/catch.hpp @@ -42,10 +42,6 @@ #include <catch2/catch_external_interfaces.h> -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -#include <catch2/benchmark/catch_benchmark.hpp> -#endif - #endif // ! CATCH_CONFIG_IMPL_ONLY #if !defined(CATCH_CONFIG_IMPL_ONLY) diff --git a/src/catch2/catch_interfaces_capture.h b/src/catch2/catch_interfaces_capture.h index 49fda7aa..0a1cfe6d 100644 --- a/src/catch2/catch_interfaces_capture.h +++ b/src/catch2/catch_interfaces_capture.h @@ -29,11 +29,9 @@ namespace Catch { struct ITransientExpression; struct IGeneratorTracker; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) struct BenchmarkInfo; template <typename Duration = std::chrono::duration<double, std::nano>> struct BenchmarkStats; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING struct IResultCapture { @@ -46,12 +44,10 @@ namespace Catch { virtual auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) virtual void benchmarkPreparing( std::string const& name ) = 0; virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; virtual void benchmarkFailed( std::string const& error ) = 0; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING virtual void pushScopedMessage( MessageInfo const& message ) = 0; virtual void popScopedMessage( MessageInfo const& message ) = 0; diff --git a/src/catch2/catch_interfaces_reporter.h b/src/catch2/catch_interfaces_reporter.h index 95b4406b..97ad6cae 100644 --- a/src/catch2/catch_interfaces_reporter.h +++ b/src/catch2/catch_interfaces_reporter.h @@ -18,10 +18,8 @@ #include <catch2/catch_option.hpp> #include <catch2/catch_stringref.h> -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) #include <catch2/benchmark/catch_estimate.hpp> #include <catch2/benchmark/catch_outlier_classification.hpp> -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING #include <string> @@ -168,7 +166,7 @@ namespace Catch { bool aborting; }; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + struct BenchmarkInfo { std::string name; double estimatedDuration; @@ -204,7 +202,6 @@ namespace Catch { }; } }; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING struct IStreamingReporter { virtual ~IStreamingReporter() = default; @@ -224,12 +221,10 @@ namespace Catch { virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) virtual void benchmarkPreparing( std::string const& ) {} virtual void benchmarkStarting( BenchmarkInfo const& ) {} virtual void benchmarkEnded( BenchmarkStats<> const& ) {} virtual void benchmarkFailed( std::string const& ) {} -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; diff --git a/src/catch2/catch_run_context.cpp b/src/catch2/catch_run_context.cpp index fe24ba10..1875468f 100644 --- a/src/catch2/catch_run_context.cpp +++ b/src/catch2/catch_run_context.cpp @@ -231,7 +231,6 @@ namespace Catch { m_unfinishedSections.push_back(endInfo); } -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) void RunContext::benchmarkPreparing(std::string const& name) { m_reporter->benchmarkPreparing(name); } @@ -241,10 +240,9 @@ namespace Catch { void RunContext::benchmarkEnded( BenchmarkStats<> const& stats ) { m_reporter->benchmarkEnded( stats ); } - void RunContext::benchmarkFailed(std::string const & error) { - m_reporter->benchmarkFailed(error); - } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + void RunContext::benchmarkFailed(std::string const & error) { + m_reporter->benchmarkFailed(error); + } void RunContext::pushScopedMessage(MessageInfo const & message) { m_messages.push_back(message); diff --git a/src/catch2/catch_run_context.h b/src/catch2/catch_run_context.h index 348ef32a..d51260ab 100644 --- a/src/catch2/catch_run_context.h +++ b/src/catch2/catch_run_context.h @@ -82,12 +82,10 @@ namespace Catch { auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) void benchmarkPreparing( std::string const& name ) override; void benchmarkStarting( BenchmarkInfo const& info ) override; void benchmarkEnded( BenchmarkStats<> const& stats ) override; void benchmarkFailed( std::string const& error ) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING void pushScopedMessage( MessageInfo const& message ) override; void popScopedMessage( MessageInfo const& message ) override; diff --git a/src/catch2/catch_test_macros.hpp b/src/catch2/catch_test_macros.hpp index ba884cde..0dd41bf5 100644 --- a/src/catch2/catch_test_macros.hpp +++ b/src/catch2/catch_test_macros.hpp @@ -98,12 +98,10 @@ #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) #define CATCH_BENCHMARK(...) \ INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) #define CATCH_BENCHMARK_ADVANCED(name) \ INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name) -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required #else @@ -197,12 +195,10 @@ #define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) #define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) #define BENCHMARK(...) \ INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) #define BENCHMARK_ADVANCED(name) \ INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name) -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING #else // CATCH_CONFIG_DISABLE diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index 0b407346..e091225e 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -431,7 +431,6 @@ void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { StreamingReporterBase::sectionEnded(_sectionStats); } -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) void ConsoleReporter::benchmarkPreparing(std::string const& name) { lazyPrintWithoutClosingBenchmarkTable(); @@ -477,7 +476,6 @@ void ConsoleReporter::benchmarkFailed(std::string const& error) { << "Benchmark failed (" << error << ')' << ColumnBreak() << RowBreak(); } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { m_tablePrinter->close(); diff --git a/src/catch2/reporters/catch_reporter_console.h b/src/catch2/reporters/catch_reporter_console.h index 34c14f8f..5ee9663c 100644 --- a/src/catch2/reporters/catch_reporter_console.h +++ b/src/catch2/reporters/catch_reporter_console.h @@ -41,12 +41,10 @@ namespace Catch { void sectionStarting(SectionInfo const& _sectionInfo) override; void sectionEnded(SectionStats const& _sectionStats) override; -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) void benchmarkPreparing(std::string const& name) override; void benchmarkStarting(BenchmarkInfo const& info) override; void benchmarkEnded(BenchmarkStats<> const& stats) override; void benchmarkFailed(std::string const& error) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING void testCaseEnded(TestCaseStats const& _testCaseStats) override; void testGroupEnded(TestGroupStats const& _testGroupStats) override; diff --git a/src/catch2/reporters/catch_reporter_listening.cpp b/src/catch2/reporters/catch_reporter_listening.cpp index 0eb70e12..01335a49 100644 --- a/src/catch2/reporters/catch_reporter_listening.cpp +++ b/src/catch2/reporters/catch_reporter_listening.cpp @@ -44,13 +44,12 @@ namespace Catch { m_reporter->reportInvalidArguments( arg ); } -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) void ListeningReporter::benchmarkPreparing( std::string const& name ) { - for (auto const& listener : m_listeners) { - listener->benchmarkPreparing(name); - } - m_reporter->benchmarkPreparing(name); - } + for (auto const& listener : m_listeners) { + listener->benchmarkPreparing(name); + } + m_reporter->benchmarkPreparing(name); + } void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { for ( auto const& listener : m_listeners ) { listener->benchmarkStarting( benchmarkInfo ); @@ -64,13 +63,12 @@ namespace Catch { m_reporter->benchmarkEnded( benchmarkStats ); } - void ListeningReporter::benchmarkFailed( std::string const& error ) { - for (auto const& listener : m_listeners) { - listener->benchmarkFailed(error); - } - m_reporter->benchmarkFailed(error); - } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + void ListeningReporter::benchmarkFailed( std::string const& error ) { + for (auto const& listener : m_listeners) { + listener->benchmarkFailed(error); + } + m_reporter->benchmarkFailed(error); + } void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) { for ( auto const& listener : m_listeners ) { diff --git a/src/catch2/reporters/catch_reporter_listening.h b/src/catch2/reporters/catch_reporter_listening.h index 94c22951..e33aa283 100644 --- a/src/catch2/reporters/catch_reporter_listening.h +++ b/src/catch2/reporters/catch_reporter_listening.h @@ -31,12 +31,10 @@ namespace Catch { void reportInvalidArguments(std::string |