views:

745

answers:

5

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?

A: 

Just a guess but I would assume that the release build would take longer in most cases because of optimization.

chills42
+8  A: 

Well, there are a number of variables that could affect things. Here are some reasons Debug could be faster:

  • Usually Debug mode does a lot less optimizations, as those can mess up the mapping between instructions and lines of code. So, the compiler is doing less work there.
  • Even if a full debug build is slower, Debug builds happen a lot more often and can usually take advantage of incremental builds a lot more than Release build can. So fairly often a Debug build doesn't have to do nearly as much work as a Release build would.
Herms
A: 

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

Edison Gustavo Muenz
+1  A: 

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.

Vatine
A: 

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.

Steve Rowe