Only just begun reading, but should be wary of "old" optimization guides. Many common micro-optimization tricks have been made redundant by improved compilers. Many of my "speed hacks" were completely useless (or even worsening) once I upgraded to VS2010.
My suggestion would be making small examples yourself and testing them on your compiler.
thanks for reply Gaminic, Many of my "speed hacks" were completely useless
whell that's because you allready had the knowelede of making your code as short as possible.
By the way, I'm very interested in what you're programming if these tricks get you a 50% speedup.
I din't say that this book speeds my programs up to 50%
but I see alot of beginers are writing a code which could be wrten in 2x or 3x less code!
so I thought maybe someone can find that book interesting :)
"old" optimization guides
old optimization guides??
for every new programer who just started learning C++ this are very new things.
Writing time is pretty much a useless measure. The time spent thinking far outweighs the actual typing time anyway. I'm not certain how you drew the "less typing" conclusion. How exactly would a jump-table or reversing loops reduce the required amount of typing?
Anyway, "fast code", like Catfish said, is code that executes fast. A common example is sorting: a BubbleSort algorithm can be written in <5 lines of code, but it is [for non-trivial cases] much, much slower than QuickSort, even though QuickSort is going to require quite a few more lines to implement.
This might also clarify my previous post a bit more: these optimization tricks are "old", because compilers have gotten much, much smarter. If a jump-table is generally faster than if-then-else or switch constructs, you can be quite certain that most modern compilers will generate the same assembly code for either version. Reversing loop order is one of the few things I'm certain of that have lost their purpose between VS2008 and VS2010.
Usually it does. The more instructions a program contains
1. The longer it will likely take to execute them, although 10 instructions that each take 2 cycles to complete is faster than 5 instructions that each take 5 cycles to complete.
2. The more instruction cache misses there will probably be
Complexity is probably a better estimator, though.
@chrisname: Why would you bring up machine code in this discussion? That is by far the least useful measure to go by, considering nobody ever gets to see or touch it.
If by line you mean sequence point, then it depends on optimizations.
If by line you mean line, then I shall write my entire program on one line. Or should I put a new line every time I am allowed whitespace? :p