Skip to content

Commit fd31a62

Browse files
committed
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.
1 parent 4df8fee commit fd31a62

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

benchmarks/runtime_assertion_benches.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,48 @@
77
// SPDX-License-Identifier: BSL-1.0
88

99
#include <catch2/catch_test_macros.hpp>
10+
#include <catch2/matchers/catch_matchers_templated.hpp>
1011

11-
TEST_CASE("Simple REQUIRE - 10M") {
12-
for (size_t i = 0; i < 10'000'000; ++i) {
13-
REQUIRE(true);
12+
namespace {
13+
14+
class MatchAllMatcher final : public Catch::Matchers::MatcherGenericBase {
15+
public:
16+
template <typename Any>
17+
bool match( Any&& ) const {
18+
return true;
19+
}
20+
21+
std::string describe() const override {
22+
using namespace std::string_literals;
23+
return "Long string that does not fit into SSO"s;
24+
}
25+
};
26+
27+
MatchAllMatcher MatchAll() { return MatchAllMatcher(); }
28+
29+
30+
TEST_CASE( "REQUIRE", "[assertions]" ) {
31+
for ( size_t i = 0; i < 10'000'000; ++i ) {
32+
REQUIRE( true );
1433
}
1534
}
1635

17-
TEST_CASE("Simple NOTHROW - 10M") {
18-
for (size_t i = 0; i < 10'000'000; ++i) {
19-
REQUIRE_NOTHROW([](){}());
36+
TEST_CASE( "REQUIRE_THAT", "[assertions][matchers]" ) {
37+
for ( size_t i = 0; i < 10'000'000; ++i ) {
38+
REQUIRE_THAT( 1, MatchAll() );
2039
}
2140
}
2241

23-
TEST_CASE("Simple THROWS - 10M") {
24-
for (size_t i = 0; i < 10'000'000; ++i) {
25-
REQUIRE_THROWS([]() { throw 1; }());
42+
TEST_CASE( "REQUIRE_NOTHROW", "[assertions][exceptions]" ) {
43+
for ( size_t i = 0; i < 10'000'000; ++i ) {
44+
REQUIRE_NOTHROW( []() {}() );
2645
}
2746
}
47+
48+
TEST_CASE( "REQUIRE_THROWS", "[assertions][exceptions]" ) {
49+
for ( size_t i = 0; i < 10'000'000; ++i ) {
50+
REQUIRE_THROWS( []() { throw 1; }() );
51+
}
52+
}
53+
54+
} // namespace

0 commit comments

Comments
 (0)