什么是已知的C / C ++为GCC优化 [英] What are the known C/C++ optimizations for GCC

查看:258
本文介绍了什么是已知的C / C ++为GCC优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多code的,我需要优化,使其运行速度更快。我用的 Ø$ P $支持度 以告诉我哪里有code花费了大量的时间。我用下面的命令来获取统计信息。

I am have a lot of code that I need to optimize and make it run faster. I used opreport to tell me where the code spends a lot of time. I use the following command to get the statistics

opreport -g -l -d

建议以获得更好的统计数据是使用不同的标志pciated AP $ P $,也许发现它每行数字,而不是功能号码。

Suggestions to get better statistics are appreciated using different flags, perhaps find it per line number instead of function number.

所以很多问题,我觉得我看到的是在以下方面:

So a lot of issues that I "think" I see are in regard to:


  • 三分球,多维数组

  • 乘法

  • 循环

我想编译器更好地优化code,从而帮助他。我有些因素code块插入函数字限制地告诉编译器,我的指针数组不重叠。

I want compiler to optimize the code better, thus helping him. I factored some code blocks into function with word restrict to tell compiler that my pointer arrays don't overlap.

,所以我我要找(一)常见的C结构,可以使code运行的时间更长和(b)如何帮助编译器优化code。

SO I am I am looking for (a) common C constructs that can make code run longer and (b) how to help compiler optimize code.

感谢

推荐答案

谨防从分析工具的报告,他们可能会产生误导。例如,考虑做大量的字符串比较别的都不需要的应用程序。报告是要告诉你,你花> 90%的时间在字符串比较功能。所以很自然,你决定实施code的优化版本只找出了分析器告诉你,你的还是的支出90%的时间在那里(因为这是所有的程序的确...)。

Beware of the reports from profiling tools, they can be misleading. For instance, consider an application that does a large amount of string comparisons and not much else. A report is going to tell you that you spend >90% of your time in string comparison functions. So naturally, you decide to implement an optimized version of that code only find out that the profiler tells you that you are still spending 90% of your time there (because that is all your program does...).

您必须有你的应用的深入了解和应用,为探查否则你可能会浪费精力。

You have to have intimate knowledge of your application and apply that to a profiler else you might be wasting effort.

今天做的编译器优化(尤其是有额外的标志作为选项)的一个相当不错的工作。这是不可能的,你会从什么在语言层面获益(即你如何处理数组) - 你可能要读/​​写ASM如果要调整手的东西。

Compilers today do a fairly good job of optimizing (especially with extra flags as options). It is unlikely that you will benefit from anything at a language level (i.e. how you handle arrays) - you will probably have to read/write asm if you want to hand tune things.

这篇关于什么是已知的C / C ++为GCC优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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