If you code up an algorithm as O(N3) no compiler is going to magically figure out that a better O(N log N) algorithm exists. You need to attend lectures and learn about algorithms. |
That's specifically why I said "I'm sure some of the optimizations can't be reflected in the code, but it probably has some code optimizations that were important."
One such optimization I found in the assembly on godbolt was a line that did work which would have been discarded anyway. In this way, some optimizations are in fact changing your code.
You need to attend lectures and learn about algorithms. |
The algorithm I'm using can't be changed - I'm only changing minor details to gain performance. So far, I've shaved about .5 seconds - still trying to get more performance out of it.
From previous experience, little things you wouldn't think matters can make huge performance gains. Many times that doesn't matter once optimizations are turned on though.
(1) If a std:: library routine exists that will do exactly what you want, then use it; those library routines, particularly those in <algorithm>, will have been honed and polished to be fast. |
I've been doing the opposite - getting rid of std:: functions I conveniently used and creating my own where appropriate. There are a lot of functions that are just too slow.
Then the compiler - not you - can do tricks like re-ordering the calculations, or multi-threading, or vectorising. |
The whole point is that I'm trying to optimize the code myself for maximum performance when it is run somewhere I don't have access to such optimizations.
Do you mean that your c++ source code is going to be compiled with different compilers and that the non-Microsoft one used doesn't provide the same low-level code optimisations? |
Yes, exactly. And I need to run the code in the other environment and I can't simply bring the executable over.
The part of the code I'm trying to optimize is a recursive function doing some path-finding. I was trying to decrease the amount of recursive calls needed. That started to dry out - then I found that replacing some of those std:: functions gave a lot of performance boosts so I've been working on that.
I'm sure many std:: functions may give better performance than coding them myself if optimizations were turned on, but that's just how it is.
EDIT: The weakest link that I'm trying to fix right now is my string use. I have a string that gets edited (I add and erase from it) every recursive call. Removing that improves my speed 2x. Once I have a better alternative for editing this string, the code should be as fast as I need it to be.