Should I use any optimization flag when creating my application?
Absolutely! Even the optimization, rotated to the lowest level, -O1 for GCC / clang / icc, is likely to surpass most of your optimization efforts. Basically, for free, so why not?
I am using gcc4.6.3.
GCC 4.6 is old. You should consider working with modern tools, unless you are limited.
But I have not seen an improvement with this (I have some performance tests).
You have not seen any visible performance improvements, which is very common when working with such micro-optimizations. Unfortunately, achieving modern improvements is not so easy with today's equipment: this is because we have faster (incredibly fast) components than before. Thus, saving cycles is not as smart as before.
Despite the fact that it is worth noting that consecutive microoptimizations can make your code much faster, as in tight loops. Avoiding stalls, incorrect industry predictions, maximizing cache usage make a difference when processing pieces of data. And SO the most voted question clearly shows that.
This is even stated in the GCC manual:
- Built-in function: long __builtin_expect (long exp, long c)
You can use __builtin_expect to provide branch prediction information to the compiler. In general, you should prefer to use the actual feedback for this (-fprofile-arcs), as programmers are known to poorly predict how their programs actually execute. However, there are applications in which this data is difficult to collect.
(my emphasis)
source share