请问gcc的-g调试标志影响程序执行的? [英] Does the gcc -g debugging flag affect program execution?

查看:409
本文介绍了请问gcc的-g调试标志影响程序执行的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚测试程序我工作,我看到它的执行速度为3μs(统计上显著变化)当我-g编译它。这是没有意义的我 - 我认为-g标志不应该影响到程序的执行,而且即使它会使其运行速度慢,不是越快

I've just been testing a program I'm working, and I see that it's executing 3μs faster (a statistically significant change) when I compile it with -g. This makes no sense to me - I thought that the -g flag wasn't supposed to affect the program execution, and that even if it did it would make it run slower, not faster.

谁能告诉我为什么发生这种情况?以及它是否改变了程序执行流程?我不跟-O编译,因为我需要书面它究竟执行,但如果-g能以某种方式使其运行与不断变化的我显然应该使用的指令顺序更快。

Can anyone tell me why this is happening? And whether it changes the programs execution flow? I am not compiling with -O because I need it to execute exactly as written, but if -g can somehow make it run faster with changing the instruction order I should obviously be using that.

所以,我需要知道到底是什么改变了-g标志,使该方案。

So I need to know exactly what changes the -g flag makes to the program.

编辑:更多的测试,我跑,t值变得越大(=更多的统计学显著的差异变)。这绝对不是测量误差 - 有些事情正在发生

The more tests I run, the bigger the t-value gets (= the more statistically significant the difference becomes). This is definitely not measurement error - something is going on.

推荐答案

正如其他人所说,调试符号不会,除非有在编译器的(不太可能)错误更改code的控制流。

As others have said, debugging symbols will not change the control flow of your code unless that there is an (unlikely) bug in the compiler.

它改变了执行,但是,因为可执行文件变大,并且执行code为S $ P $垫更广泛地在更多的网页。你可以期待更多的高速缓存未命中和IO信号。在多任务环境中(甚至在Linux / busybox的系统是这样的事)这可能会导致稍有不同的调度行为。

It changes execution, though, because the executable becomes bigger, and the executed code is spread more widely on more pages. You can expect more cache misses and IO signals. On a multi-tasking environment (and even a Linux/busybox system is such a thing) this can result is slightly different scheduling behavior.

在另一方面,测量这种微小的时间差,你形容他们是在自己的权利的艺术。你可能在海森堡的设置,在您的测量影响执行时间。您的测量可能会出现统计上显著的偏差,但我会在跨$ P $非常小心pting他们的话说某某选项使速度更快code。

On the other hand, measuring such tiny time differences as you describe them is an art in its own rights. You are probably in an Heisenberg setting, where your measurements influence execution times. Your measurements may show statistically significant deviation, but I would be extremely careful in interpreting them as saying such and such option makes faster code.

这篇关于请问gcc的-g调试标志影响程序执行的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆