A great read, but times have changed a lot. The only truly general advice about optimization is "profile your code, try to make the slowest bits faster, then re-profile your code to see whether it worked."
As I understand it (and I'm not an optimization specialist so I could be off-base here) on modern compilers and on desktop or server computers you want to avoid micro-optimizations like the ones listed here because the compiler does all that and more, and knows far more about the CPU you're running on, the states of the registers, etc than you do. Stick with making your code more efficient, precomputation, caching, algorithmic optimisations (for instance choose an O(n2) algorithm over an O(n3) algorithm and stay the heck away from exponential and higher orders unless really necessary). When you need that last 10% the top things to look at are cache performance and branch prediction type stuff. And again, always profile because you can get the weirdest interactions going on. Your intuition may/will be wrong but the numbers don't lie. Usually.
3 comments
0 u/svipbo [OP] 28 Dec 2015 11:10
A word of warning: this article is quite old (1999), but most of it appears to be still valid.
0 u/tame 28 Dec 2015 14:51
A great read, but times have changed a lot. The only truly general advice about optimization is "profile your code, try to make the slowest bits faster, then re-profile your code to see whether it worked."
As I understand it (and I'm not an optimization specialist so I could be off-base here) on modern compilers and on desktop or server computers you want to avoid micro-optimizations like the ones listed here because the compiler does all that and more, and knows far more about the CPU you're running on, the states of the registers, etc than you do. Stick with making your code more efficient, precomputation, caching, algorithmic optimisations (for instance choose an O(n2) algorithm over an O(n3) algorithm and stay the heck away from exponential and higher orders unless really necessary). When you need that last 10% the top things to look at are cache performance and branch prediction type stuff. And again, always profile because you can get the weirdest interactions going on. Your intuition may/will be wrong but the numbers don't lie. Usually.
0 u/morealll 04 Jan 2016 12:29
Nice...