diff options
| author | Martin Hořeňovský | 2026-08-22 15:19:33 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-08-22 20:43:13 +0200 |
| commit | 45f9ea1e798c2e128dcba53602ccbddfe5676f6f (patch) | |
| tree | 3eb107a59de8a5654109fc594ee29b3e5c57770d /tests | |
| parent | 9915f7250dcfc2c7bbd9e86c83b29438df39d856 (diff) | |
| download | catch3-45f9ea1e798c2e128dcba53602ccbddfe5676f6f.tar.gz | |
Add optimizer barrier to benchmark calls of void-returning functions
The goal is to do the equivalent of clobbering memory, which forces
the compiler to keep side effects that are external to the benchmarked
function, while allowing it to optimize inside the benchmarked function.
E.g. this cannot be optimized away:
```cpp
BENCHMARK("foo") {
global_count += 1;
};
```
while this can:
```cpp
BENCHMARK("bar") {
size_t local_count = 0;
for (size_t i = 0; i < 100; ++i) {
local_count += 1;
}
};
```
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 13 | ||||
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp | 3 |
2 files changed, 0 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a74a9d0..469e3f3d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -486,19 +486,6 @@ set_tests_properties("Benchmarking::SkipBenchmarkMacros" FAIL_REGULAR_EXPRESSION "benchmark name" ) -add_test(NAME "Benchmarking::FailureReporting::OptimizedOut" - COMMAND - $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "empty" -r xml - # This test only makes sense with the optimizer being enabled when - # the tests are being compiled. - CONFIGURATIONS Release -) -set_tests_properties("Benchmarking::FailureReporting::OptimizedOut" - PROPERTIES - PASS_REGULAR_EXPRESSION "could not measure benchmark\, maybe it was optimized away" - FAIL_REGULAR_EXPRESSION "successes=\"1\"" -) - add_test(NAME "Benchmarking::FailureReporting::ThrowingBenchmark" COMMAND $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "throw" -r xml diff --git a/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp b/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp index 69251d97..b7ec17b8 100644 --- a/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp @@ -429,9 +429,6 @@ TEST_CASE("run benchmark", "[benchmark][approvals]") { } TEST_CASE("Failing benchmarks", "[!benchmark][.approvals]") { - SECTION("empty", "Benchmark that has been optimized away (because it is empty)") { - BENCHMARK("Empty benchmark") {}; - } SECTION("throw", "Benchmark that throws an exception") { BENCHMARK("Throwing benchmark") { throw "just a plain literal, bleh"; |