编译器处理包含保护的头有多贵? [英] How expensive it is for the compiler to process an include-guarded header?

查看:178
本文介绍了编译器处理包含保护的头有多贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了加速大型源文件的编译,修剪翻译单元中使用的大量标头更有意义,还是编译代码的成本远远大于处理代码所需的时间。包含保护的标题?

To speed up the compilation of a large source file does it make more sense to prune back the sheer number of headers used in a translation unit, or does the cost of compiling code far outweigh the time it takes to process-out an include-guarded header?

如果后者是真的,那么工程工作可以更好地用于创建更多的轻量级标头而不是更少。

If the latter is true an engineering effort would be better spent creating more, lightweight headers instead of less.

那么现代编译器处理有效包含保护的头文需要多长时间?包含这样的标题会在什么时候成为编辑性能的一个点?

So how long does it take for a modern compiler to handle a header that is effectively include-guarded out? At what point would the inclusion of such headers become a hit on compilation performance?

(与这个问题

推荐答案

答案:

它可能非常昂贵!

It can be very expensive!

I发现了一篇文章,其中有人对这里解决的问题进行了一些测试,如果你正确编写了包含保护,你会惊讶地发现你可以在MSVC下增加你的编译时间至少一个数量级

I found an article where someone had done some testing of the very issue addressed here, and am astonished to find you can increase your compilation time under MSVC by at least an order of magnitude if you write your include guards properly:

http:// www .bobarcher.org / software / include / index.html

结果中最令人惊讶的一行是在MSVC 2008下编译的测试文件来自5.48如果权利包括保护方法,则为0.13秒。

The most astonishing line from the results is that a test file compiled under MSVC 2008 goes from 5.48s to 0.13s given the right include guard methodology.

这篇关于编译器处理包含保护的头有多贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆