c - 海湾合作委员会 : Compiling with basic debbuging information added (flag -g) what are the effects on the performance?

标签 c performance debugging makefile

我最近检查了一些由一些在该领域(编程等)非常熟练的作者制作的Makefile。这些 makefile 适用于在 Linux 系统上使用 gcc 编译器编译的程序。

在其中一些文件中,我在 CCFLAGS 和 LDFLAGS 选项中发现了“-g”标志,即使在非调试目标中也是如此。我想知道它的作用,发现它向代码添加了一些基本的调试信息。

我想知道对性能有什么负面影响?我是否应该更好地将它们从我自己的非调试目标中删除,或者当实际没有使用调试器或分析器时负面影响可以忽略不计?

最佳答案

-g 参数本身不应对程序的性能产生负面影响:

GCC allows you to use -g with -O. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops.

(参见 https://gcc.gnu.org/onlinedocs/gcc-4.4.6/gcc/Debugging-Options.html#Debugging-Options )

因此,您可以将 -g-O 结合起来,尽管您应该被警告,上面提到的奇怪的事情可能会发生。因此,总的来说,将发布代码与调试符号结合起来是没有意义的,除非您尝试在客户站点上调试代码。但当您这样做时,您可能不会获得最佳的调试体验。

但请记住,调试会大大增加程序的文件大小。

如果有任何预期的副作用,您只能通过您的实现进行基准测试,您无法将其他人获得的知识转移到您的代码/算法中。

关于c - 海湾合作委员会 : Compiling with basic debbuging information added (flag -g) what are the effects on the performance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244292/

相关文章:

Python ctypes对齐数据结构

c - 简单的输入。程序崩溃

performance - 使用 commitWithin 的 Solr 性能没有意义

ruby-on-rails - 使用 better_errors 作为调试器?

C# 二叉搜索树 - 堆栈溢出 - 调试

c - 字符串如何隐式类型转换为字符?

c - 如何手动执行单元测试?

javascript - 大量的 mongodb 动态集合对于项目来说是一件坏事并且对性能有影响

performance - Amazon S3,为什么默认关闭日志记录,打开它有什么影响?

c - 使用 gdb 64bit 越界检查内存