This is a benchmark that is relevant only to single header and header only frameworks - like doctest and Catch.
The benchmark is done with this script only under Windows (but can be adapted for Unix) using CMake.
It should be noted that GCC performs much better under Unix.
The script generates 501 source files and in 500 of them makes a function in the form of int f135() { return 135; }
and in main.cpp
it forward declares all the 500 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
/mingw32-make
+ implementation - only in main.cpp
the header is included with a #define
before it so the test runner gets instantiated:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" ```
baseline | + implementation | + header everywhere | + a test everywhere | + disabled | |
---|---|---|---|---|---|
MSVC Debug | 14.2 | 15.1 | 18.3 | 21.4 | 15.6 |
MSVC Release | 13.4 | 14.5 | 18.7 | 23.2 | 15.2 |
GCC Debug | 22.7 | 24.1 | 29.2 | 38 | 25 |
GCC Release | 22.9 | 25 | 30 | 45 | 25 |
baseline | + implementation | + header everywhere | + a test everywhere | ||
---|---|---|---|---|---|
MSVC Debug | 14.2 | 17 | 242 | 249 | |
MSVC Release | 13.4 | 17.7 | 231 | 264 | |
GCC Debug | 22.7 | 36.7 | 178 | 189 | |
GCC Release | 22.9 | 31.5 | 163 | 193 |
So on a modern developer machine:
implementation - baseline
doctest.h
in one source file costs below 9ms (header_everywhere - implementation) / 500
(a_test_everywhere - header_everywhere) / 500
(below 18ms for MinGW-w64 but Linux GCC will be much faster)disabled - baseline
implementation - baseline
(~12 seconds for MinGW-w64 but Linux GCC will be much faster)catch.hpp
in one source file costs around 430ms (header_everywhere - implementation) / 500
(below 280ms for MinGW-w64 which is really odd)(a_test_everywhere - header_everywhere) / 500
So if doctest.h
costs 8ms and catch.hpp
costs 430ms on MSVC - then doctest 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 doctest is so light on compile times is because it forward declares everything and doesn't drag any standard headers in the source files (except for the source file where the test runner gets instantiated). This was a design decision from day 1.
Compilers used:
Environment used - Windows 7 on an SSD, Intel i7 3770k, 16g RAM
Date: 2016.05.22
doctest version: 1.0.0
Catch version: 1.5.4
Room temperature: 18°C