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
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:
- pointers, multidimensional arrays
- multiplications
- loops
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.
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.
Thanks
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.
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.