Skip to content

Commit 5f47160

Browse files
committed
Add benchmark for catch_test_macros.hpp inclusion
1 parent e83528c commit 5f47160

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

benchmarks/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ add_executable(AssertionsSlowPath
99
assertion_listener.cpp
1010
)
1111

12+
add_executable(EmptyExecutable
13+
only_include.cpp
14+
)
15+
1216
target_link_libraries(AssertionsFastPath PRIVATE Catch2::Catch2WithMain)
1317
target_link_libraries(AssertionsSlowPath PRIVATE Catch2::Catch2WithMain)
18+
target_link_libraries(EmptyExecutable PRIVATE Catch2::Catch2WithMain)
1419

15-
list(APPEND CATCH_TEST_TARGETS AssertionsFastPath AssertionsSlowPath)
20+
list(APPEND CATCH_TEST_TARGETS AssertionsFastPath AssertionsSlowPath EmptyExecutable)
1621
set(CATCH_TEST_TARGETS ${CATCH_TEST_TARGETS} PARENT_SCOPE)

benchmarks/only_include.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Copyright Catch2 Authors
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE.txt or copy at
5+
// https://www.boost.org/LICENSE_1_0.txt)
6+
7+
// SPDX-License-Identifier: BSL-1.0
8+
9+
/**\file
10+
* "empty" include of catch_test_macros.hpp
11+
*
12+
* This file does only one thing: include `catch2/catch_test_macros.hpp`,
13+
* so that we can measure the compilation cost of the header.
14+
*/
15+
16+
#include <catch2/catch_test_macros.hpp>

benchmarks/readme.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ hyperfine --warmup 2 --shell none --parameter-list version old,new '/home/xarn/b
4949
```
5050

5151
**Compare performance of `REQUIRE` with stringification enabled, release build**
52-
```
52+
```text
5353
hyperfine --warmup 2 --shell none --parameter-list version old,new '/home/xarn/benches/Catch2-{version}/build-release/benchmarks/AssertionsFastPath -s -o /dev/null "REQUIRE"'
5454
```
5555
_Note that we redirect the output to `/dev/null` to reduce the overhead of the actual output printing, to see just the impact of stringification._
@@ -60,8 +60,18 @@ _Note that we redirect the output to `/dev/null` to reduce the overhead of the a
6060
As tests are often iterated upon and relinked, the compilation cost of
6161
Catch2 is also important.
6262

63+
64+
### Examples
65+
66+
**Compare overhead of including `catch_test_macros.hpp`**
67+
```text
68+
hyperfine --warmup 2 --shell none --parameter-list version old,new '/usr/bin/c++ -I/home/xarn/benches/Catch2-{version}/src/catch2/.. -I/home/xarn/benches/Catch2-{version}/build-debug/generated-includes -g -o /dev/null -c /home/xarn/benches/Catch2-{version}/benchmarks/only_include.cpp'
69+
```
70+
71+
**Compare build time of Catch2's `SelfTest` test suite, Debug build**
72+
```text
73+
hyperfine --warmup 2 --parameter-list version old,vas --prepare 'find ~/benches/Catch2-{version}/tests/SelfTest -type f -name "*.cpp" -exec touch {} +' 'ninja -j 1 -C ~/benches/Catch2-{version}/build-debug'
74+
```
75+
6376
TODO:
64-
* Single file vs test suite build
65-
* Practical examples
66-
* Include-only overhead
67-
* Link-only example
77+
* Link-only recipe

0 commit comments

Comments
 (0)