diff options
| author | Martin Hořeňovský | 2026-05-06 22:32:25 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-05-07 10:18:21 +0200 |
| commit | fd31a62547e2f4f217dda2e1312b36f369af7252 (patch) | |
| tree | f70257e827a34f5b8d87ac56dde2385865a56e67 | |
| parent | 4df8fee92d8ed8013a09fb0a1e3796a404a9c44b (diff) | |
| download | catch3-fd31a62547e2f4f217dda2e1312b36f369af7252.tar.gz | |
Add benchmark for REQUIRE_THAT into runtime_assertion_benches.cpp
I also changed the names of other benchmark `TEST_CASE`s so that
they are easier to use.
| -rw-r--r-- | benchmarks/runtime_assertion_benches.cpp | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/benchmarks/runtime_assertion_benches.cpp b/benchmarks/runtime_assertion_benches.cpp index 6a28e3fa..1202b0cd 100644 --- a/benchmarks/runtime_assertion_benches.cpp +++ b/benchmarks/runtime_assertion_benches.cpp @@ -7,21 +7,48 @@ // SPDX-License-Identifier: BSL-1.0 #include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_templated.hpp> -TEST_CASE("Simple REQUIRE - 10M") { - for (size_t i = 0; i < 10'000'000; ++i) { - REQUIRE(true); +namespace { + +class MatchAllMatcher final : public Catch::Matchers::MatcherGenericBase { +public: + template <typename Any> + bool match( Any&& ) const { + return true; + } + + std::string describe() const override { + using namespace std::string_literals; + return "Long string that does not fit into SSO"s; + } +}; + +MatchAllMatcher MatchAll() { return MatchAllMatcher(); } + + +TEST_CASE( "REQUIRE", "[assertions]" ) { + for ( size_t i = 0; i < 10'000'000; ++i ) { + REQUIRE( true ); } } -TEST_CASE("Simple NOTHROW - 10M") { - for (size_t i = 0; i < 10'000'000; ++i) { - REQUIRE_NOTHROW([](){}()); +TEST_CASE( "REQUIRE_THAT", "[assertions][matchers]" ) { + for ( size_t i = 0; i < 10'000'000; ++i ) { + REQUIRE_THAT( 1, MatchAll() ); } } -TEST_CASE("Simple THROWS - 10M") { - for (size_t i = 0; i < 10'000'000; ++i) { - REQUIRE_THROWS([]() { throw 1; }()); +TEST_CASE( "REQUIRE_NOTHROW", "[assertions][exceptions]" ) { + for ( size_t i = 0; i < 10'000'000; ++i ) { + REQUIRE_NOTHROW( []() {}() ); } } + +TEST_CASE( "REQUIRE_THROWS", "[assertions][exceptions]" ) { + for ( size_t i = 0; i < 10'000'000; ++i ) { + REQUIRE_THROWS( []() { throw 1; }() ); + } +} + +} // namespace |