-g flag changes runtime and compilation of program

192 Views Asked by At

I am writing a program that attempts to speed up a Top K filtering alogrithm using SSE and AVX SIMD instructions. I am compiling my program using icc with the flags -o3, -msse3, and -lrt, and the run-time comes out to ~30ms. However, when I put a -g flag at the end to use vtune or gdb, the time the program takes to run jumps to ~100ms.

Could someone explain why this is possibly happening? I am very confused as to why -g would change the compilation of a program.

1

There are 1 best solutions below

1
On

-g with other optimization flags such as -O3 (as opposed to the default -O0), will typically increase the size of the executable, retaining symbol names, type info, line numbers, etc., while not necessarily affecting the optimized code. Such an increase in code size, and symbol / load time of the program may be increased.

This extra debugging data can be stripped with strip [options] program.

Note that using -g with higher optimization values may result in the debugger trying to step through variables that do not exist - in that they have been optimized away. Yielding confusing results. That's not to say this feature is useless. A lot of code (packages) compiles with -g -O2 by default, giving the user some potential for debugging, or for stripping when an optimize executable / library is desired.