The benchmarks are done with this script using CMake. There are 2 benchmarking scenarios:
Compilers used:
Environment used (Intel i7 3770k, 16g RAM)
doctest version: 1.1.0 (released on 2016.09.21)
Catch version: 1.5.6 (released on 2016.06.09)
This is a benchmark that is relevant only to single header and header only frameworks - like doctest and Catch.
The script generates 201 source files and in 200 of them makes a function in the form of int f135() { return 135; }
and in main.cpp
it forward declares all the 200 such dummy functions and accumulates their result to return from the main()
function. This is done to ensure that all source files are built and that the linker doesn't remove/optimize anything.
baseline - how much time the source files need for a single threaded build with msbuild
/make
+ implement - only in main.cpp
the header is included with a #define
before it so the test runner gets implemented:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" ```
doctest | baseline | + implement | + header everywhere | + disabled |
---|---|---|---|---|
MSVC Debug | 5.9 | 7.1 | 8.3 | 7.0 |
MSVC Release | 5.4 | 6.9 | 8.7 | 6.5 |
MinGW GCC Debug | 9.4 | 11.7 | 14.4 | 11.1 |
MinGW GCC Release | 9.6 | 12.3 | 14.9 | 11.4 |
Linux GCC Debug | 6.3 | 7.1 | 10.2 | 7.4 |
Linux GCC Release | 6.5 | 8.4 | 10.8 | 7.8 |
Linux Clang Debug | 6.9 | 7.6 | 10.6 | 8.2 |
Linux Clang Release | 7.2 | 8.4 | 11.4 | 8.4 |
Catch | baseline | + implement | + header everywhere |
---|---|---|---|
MSVC Debug | 5.9 | 8.5 | 102 |
MSVC Release | 5.4 | 10.3 | 96 |
MinGW GCC Debug | 9.4 | 24.5 | 125 |
MinGW GCC Release | 9.6 | 18.4 | 113 |
Linux GCC Debug | 6.3 | 10.4 | 59 |
Linux GCC Release | 6.5 | 14.1 | 64 |
Linux Clang Debug | 6.9 | 9.8 | 64 |
Linux Clang Release | 7.2 | 12.8 | 67 |
implement - baseline
doctest.h
in one source file costs below 9ms (header_everywhere - implement) / 200
disabled - baseline
for 200 filesimplement - baseline
catch.hpp
in one source file costs around 430ms (header_everywhere - implement) / 200
So if doctest.h
costs 8ms and catch.hpp
costs 430ms on MSVC - then the doctest header is >> 54 << times lighter!
The results are in seconds and are in no way intended to bash Catch - the doctest framework wouldn't exist without it.
The reason the doctest header is so light on compile times is because it forward declares everything and doesn't drag any headers in the source files (except for the source file where the test runner gets implemented). This was a key design decision.
The script generates 11 .cpp
files and in 10 of them makes 50 test cases with 100 asserts in them (of the form CHECK(a==b)
where a
and b
are always the same int
variables) - 50k asserts! The testing framework gets implemented in main.cpp
.
CHECK(a==b)
- will add CHECK()
asserts which decompose the expression with template machinerydoctest specific:
CHECK_EQ(a,b)
- will use CHECK_EQ(a,b)
instead of the expression decomposing onesFAST_CHECK_EQ(a,b)
- will use FAST_CHECK_EQ(a,b)
instead of the expression decomposing onesDOCTEST_CONFIG_SUPER_FAST_ASSERTS
which speeds up FAST_CHECK_EQ(a,b)
even moreDOCTEST_CONFIG_DISABLE
doctest | baseline | CHECK(a==b) | CHECK_EQ(a,b) | FAST_CHECK_EQ(a,b) | +faster | +disabled |
---|---|---|---|---|---|---|
MSVC Debug | 2.5 | 21 | 16.2 | 6.7 | 4.4 | 2.2 |
MSVC Release | 2.6 | 64 | 55 | 63 | 5.3 | 1.8 |
MinGW GCC Debug | 3.2 | 77 | 52 | 29.5 | 12.2 | 1.6 |
MinGW GCC Release | 3.9 | 425 | 295 | 81 | 18.6 | 1.9 |
Linux GCC Debug | 1.3 | 72 | 48 | 20.3 | 9.5 | 0.9 |
Linux GCC Release | 2.3 | 339 | 210 | 42 | 18.3 | 1.3 |
Linux Clang Debug | 1.3 | 70 | 46 | 18.8 | 7.0 | 0.9 |
Linux Clang Release | 1.8 | 205 | 136 | 30 | 10.8 | 1.1 |
And here are Catch and doctest 1.0 which only have normal CHECK(a==b)
asserts:
Catch | baseline | CHECK(a==b) | doctest 1.0 | CHECK(a==b) | |
---|---|---|---|---|---|
MSVC Debug | 8.4 | 34 | MSVC Debug | 58 | |
MSVC Release | 9.7 | 77 | MSVC Release | 367 | |
MinGW GCC Debug | 20.5 | 115 | MinGW GCC Debug | 202 | |
MinGW GCC Release | 15.1 | 496 | MinGW GCC Release | 1257 | |
Linux GCC Debug | 7.3 | 101 | Linux GCC Debug | 204 | |
Linux GCC Release | 10.3 | 435 | Linux GCC Release | 1090 | |
Linux Clang Debug | 6.0 | 91 | Linux Clang Debug | 167 | |
Linux Clang Release | 8.5 | 159 | Linux Clang Release | 494 |
doctest 1.1:
CHECK(a==b)
asserts by roughly 3 times compared to doctest 1.0 (released 2016.05.22)CHECK(a==b)
assertsCHECK_EQ(a,b)
with no expression decomposition - around 20% faster than CHECK(a==b)
FAST_CHECK_EQ(a,b)
with no try/catch
blocks - around 30-70% faster than CHECK_EQ(a,b)
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
identifier which makes the fast assertions even faster by another 35-80%DOCTEST_CONFIG_DISABLE
identifier the assertions just disappear as if they were never written