发布与调试构建时间
我一直认为调试版本比发布版本慢,因为编译器需要额外生成调试器信息。 最近,我很惊讶地听到我的一位同事说发布版本通常需要更多时间。 (我相信这只是因为增量链接/编译)。
一般来说,两者哪个更快?
I have always believed that Debug builds are slower than Release builds since the compiler needs to additionally generate debugger information. I was recently surprised to hear one of my colleagues saying that release builds usually take more time. (I believe that it is only because of incremental linking/compiling).
In general, which of the two is faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
嗯,有很多变量可能会影响事情。 以下是调试速度更快的一些原因:
Well, there are a number of variables that could affect things. Here are some reasons Debug could be faster:
总的来说,我预计调试版本的构建速度会更快,但运行速度会更慢,而发布版本的构建时间会更长,但最终结果会运行得更快。
这取决于发布版本可能具有更积极的优化,而这些可能会干扰可调试性。 此外,一些更大规模的优化确实需要很长时间。 在目标文件中插入调试信息的时间足够小,可以忽略不计,它可能比首先从磁盘读取源代码花费的时间更少。
On the whole, I'd expect that a debug build will be faster to build, but slower to run and a release build to take longer to build, but the end result would run faster.
This is down to the release buid probably having more aggressive optimisations and these can interfer with debuggability. Also, some larger-scale optimisations do take a long time. The time to insert debug information in the object files is small enough to be ignorable, it probably takes less time than reading the source code off disk in the first place.
只是猜测,但我认为由于优化,在大多数情况下发布构建会花费更长的时间。
Just a guess but I would assume that the release build would take longer in most cases because of optimization.
调试版本通常更快,因为没有进行优化(这在发布版本中很常见)。
您可以选择不使用可执行文件生成调试符号,也不进行优化,但这对于发布版本来说会很奇怪。 虽然我认为它会构建得更快。
调试和发布之间的主要区别在于,调试旨在进行调试(因此包括调试符号),而发布旨在运行得更快,因此您可以使用强优化
The debug builds are usually faster because there is no optimization being done (which is very common in release builds).
You can opt to not generate debugging symbols with your executable and no optimization too, but that would be strange for a release build. Though it would build faster I think.
The main difference between Debug and Release is that Debug is meant for debugging (so includes debugging symbols) and Release is meant to run faster, so you use strong optimization
发布版本更快的主要原因是编译器对它们进行了大量优化。 例如,它可以展开循环、删除不必要的变量和内联函数。 优化不是一项简单的任务,需要大量的计算能力,从而减慢构建速度。
大多数编译器会让您关闭发布版本的优化。 尝试这个。 您的构建时间将会缩短。 您还可以打开调试构建的优化并查看构建时间的攀升。
The primary reason release builds will be faster is that the compiler does a lot of optimization on them. For example, it may unroll loops, remove unnecessary variables, and inline functions. Optimization is not a trivial task and takes a lot of computing power, thus slowing down the build.
Most compilers will let you turn off optimization on release builds. Try this. Your build times will shrink. You can also turn on optimization on debug builds and see your build times climb.