Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Boost.Test tests faster

I am using xcode (gcc) to compile my boost test suite and it takes too long.

The tests are minimal dummy tests, yet it takes several seconds (about 20) to compile them:

#include "boost/test/included/unit_test.hpp"

BOOST_AUTO_TEST_CASE(dummy)
{
    BOOST_CHECK_EQUAL(2+2, 4);
}

BOOST_AUTO_TEST_CASE(dummyFail)
{
    BOOST_CHECK_EQUAL(2+3, 4);
}

The manual suggests using the library version to speed up compilation. However, I am concerned this might not work - xcode already rebuilds my tests only. The whole framework isn't compiled again since the object files exist.

I guess it's the amount of header files and templates in Boost.Test that are responsible for most of the compilation time.

Do you have an idea of how to compile significantly faster? Would using it as library work? Would including only parts of boost.test work?

Any help is greatly appreciated!

like image 480
clemens Avatar asked Aug 10 '11 15:08

clemens


3 Answers

The reason it's slow to compile is because boost/test/included/unit_test.hpp is huge. Using a library makes it faster because the huge header is compiled when the library is built and not thereafter. Your tests then include a smaller set of headers, leading to shorter build times.

Because I'm too lazy to build the library, an alternative I've used is to have one source file (which never changes, and so is rarely rebuilt) include the full boost test, and then have all the real test sources include just boost/test/unit_test.hpp. That gives most of the benefits of using the library.

like image 115
Alan Stokes Avatar answered Nov 19 '22 03:11

Alan Stokes


Try using precompiled headers, this should reduce compilation time. Details can be found here: http://www.boost.org/boost-build2/doc/html/bbv2/reference/precompiled_headers.html

like image 45
Marty B Avatar answered Nov 19 '22 04:11

Marty B


I believe all the options are now described in the official documentation (see Usage variants).

The Static library usage variant is very convenient, and greatly reduces compilation times. As described there, one can create a single source file including just two lines, compile that separately and link that in with the other tests.

A comment regarding the linked docs. I believe that there is an error in that page, namely here:

One and only one translation unit should include following lines:

#define BOOST_TEST_MODULE test module name
#include <boost/test/unit_test.hpp>

This leads to "undefined reference" errors in the linking phase. I believe it should be instead:

#define BOOST_TEST_MODULE test module name
#include <boost/test/included/unit_test.hpp>
like image 1
Michele Mesiti Avatar answered Nov 19 '22 03:11

Michele Mesiti