What are the famous C / C ++ optimizations for GCC

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

opreport -g -l -d

Suggestions for obtaining better statistics are evaluated using different flags, it is possible to find them on the line number instead of the function number.

So many problems that I “think” I see regarding:

  • pointers, multidimensional arrays
  • multiplications
  • hinges

I want the compiler to better optimize the code by helping it. I have included some blocks of code in a word-limited function to tell the compiler that my pointer arrays do not overlap.

SO (a) C, , (b) .

+1
7

, . , , . , > 90% . , , , , , 90% ( , ...).

, .

( ). , - (.. ) - , , / asm, .

+6

, ++, - , . ++ ( OO) LOT .

- .

+4

- " C, " ( , , , ), , , . , , C/++, - , .

, , : (-) , .

+4

: , 90% , (, ), , . , 90%.

: opreport ( , BTW) , , . , , , .

+2

, / .
-, . , , ..:) , , .
, : . , , .

, - , , // - .. , . , , .
, : , , : , , .
, ...

+1

++ . , . int arr [100] [1000], ,

for (int = 0; < 100; ++)   for (int j = 0; j < 1000; j ++)      [] [J]

j, . , , , . , .

0

In my experience, it has little to do with which language or compiler you use, and it has everything related to how the code is designed and organized.

If you think that minor optimizations are possible, and that it really depends on the compiler, you may find this surprisingly .

This is the method I use and the explanation of why it works.

0
source

All Articles