针对编译时间进行优化的 STL 版本?
我正在寻找一种 STL 的变体(如果它不具备所有功能也没关系),该变体针对较短的编译时间进行了优化 - 我对较长的编译时间感到困扰,这会延迟我的编译 -调试-编辑循环。
我主要对 STL 的容器感兴趣:矢量/地图,而不是算法。
谢谢!
I'm looking for a variant of the STL (it's okay if it doesn't have all the functionality) that's optimized for short compile times -- I get bothered by long compile times that delay my compile-debug-edit cycle.
I'm mainly interested in the containers of the STL: vector/map, and not so much the algorithms.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于您只对 STL 的一部分感兴趣,因此您是否考虑过对头文件进行分支,以便不包含未使用的内容。
Since you're only interested in part of the STL, have you considered branching the header files so that the unused stuff is not included.
买一台更快的电脑? :) 说真的,我们发现模板确实会消耗链接时间。为了解决这个问题,我们只将当前正在调试的模块保留为完全调试模式(-o0)。我们将其他模块编译为高于 0 的优化级别,不会生成几乎那么多的死代码供链接器解析。
Buy a faster computer? :) Seriously though, we've found that templates really eat up link times. To get around this, we only leave the modules we are currently debugging in full debug mode (-o0). The other modules we compile to some optimization level above 0 that doesn't generate nearly as much dead code for the linker to resolve.
查看编译器的预编译头选项。 在 GCC 中,例如,传递标头,就好像它是源一样导致它被预编译。
它显着减少了我的小测试的时间,但前提是您不计算预编译所花费的时间:
Take a look at your compiler's options for precompiled headers. In GCC, for example, passing a header as if it is a source causes it to be precompiled.
It reduced time significantly for my little test, but only if you don't count the time spent precompiling:
由于 STL 严重依赖模板,因此真正让您感兴趣的是编译器处理基于模板的代码的速度。 GCC 在每个新版本中都在提高编译模板代码的速度,因此您可能需要考虑更新编译器。但除此之外,您无法做太多事情来加速基于模板的代码。其他一些编译标志可以提高构建速度;例如,省略优化标志将使其编译速度更快,而使用预编译头也可以大大加快编译速度。如果您有一台具有多个内核的计算机,则许多构建系统都支持并行编译(例如,make 使用“-j”标志(如“-j 2”中所示)来指定有多少个内核)。我还应该指出,您只需为您使用的内容付费;如果您包含;和<地图>但不是,那么您根本不需要为其付费...因此,如果您包含它但不使用它,那么请停止包含它。
Since STL relies heavily on templates, what will really get you is how fast the compiler is capable of processing template-based code. GCC has been improving its speed at compiling template code with each new release, so you might want to consider updating your compiler. Short of that, though, there isn't much you can do to speed up template-based code. Some other compilation flags can improve the build speed; for example, omitting the optimization flag will make it compile faster, and using precompiled headers can also greatly speed up compilation. If you have a computer with multiple cores, many build systems support compilation in parallel (for example, make uses the "-j" flag as in "-j 2" to specify how many cores). I should also point out that you only pay for what you use; if you include <vector> and <map> but not <algorithm>, then you won't be paying for it at all... so if you are including it but not using it, then stop including it.