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?
-
You may have a look at precompiled header.user2672107– user26721072017-11-29 07:47:43 +00:00Commented Nov 29, 2017 at 7:47
-
2If 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.Peter– Peter2017-11-29 13:22:32 +00:00Commented Nov 29, 2017 at 13:22
-
Improving Compilation Time of C/C++ Projectsmilahu– milahu2022-01-25 15:38:29 +00:00Commented Jan 25, 2022 at 15:38
Add a comment
|
1 Answer
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).