3

My project compilation speed is slow due to the unit tests using a lot of macros (maybe with boost test library). From gcc -ftime-report, it shows the preprocessing time cost is high. Are there any ways to optimize the speed for this?

3
  • You may have a look at precompiled header. Commented Nov 29, 2017 at 7:47
  • 2
    If you make heavy use of macros, expect the preprocessor to do more work. Without information about your code, or the macros, or how you are USING those macros (heavy macro usage makes the preprocessor work harder, since macro expansion/substitution is THE job of the preprocessor) it is impossible to give useful advice. The general solution would be: avoid using macros, but alternatives have costs too - such as writing repetitive code (labour intensive, error prone) or using different techniques (templates, etc) that make the compiler do more work after preprocessing. Commented Nov 29, 2017 at 13:22
  • Improving Compilation Time of C/C++ Projects Commented Jan 25, 2022 at 15:38

1 Answer 1

1

It really depends on your macros, but the general idea is to reduce the number of times you expand them

For example if you were using Catch, a good idea is to put the common part of the test suite in a separate, shared file (https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md#scaling-up).

I have never used the boost test library, but apparently they give similar suggestions (http://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/utf/usage-recommendations/generic.html).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.