Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release build vs. Debug build performance [closed]

Is the Release Build always faster than the Debug build (because, the release build is optimizing a lot)?, even if I write the fastest performance code possible?

Or is it possible to write C++ code (using debug) which is as fast as the Release Build?

I'm just curious if my code Is too slow, because I notice a respectable difference, when I do performance tests.

like image 335
jeromintus Avatar asked Aug 29 '14 20:08

jeromintus


1 Answers

A good choice of algorithm definitely will make a big difference in speed of a debug build, but debug builds will never be as fast. It's because the optimizer schedules registers completely differently, trying to make code run fast, while the debug compiler tries to preserve values of temporary variables so you can read them from the debugger.

Since you probably have a lot more variables than CPU registers, this means the debug compiler will emit instructions to copy those values to RAM. While in a release build, if the value isn't used again, the optimizer will just throw it away.

like image 60
Ben Voigt Avatar answered Sep 28 '22 15:09

Ben Voigt