Further Optimizations
Several other techniques exist that can be implemented as you code; some of them are not guaranteed to produce better code, but it takes very little effort to change your coding habits to do these reflexively. They cost nothing but may result in gains. A few of these techniques are as follows:
- Pass parameters that are not primitive types by const reference when possible. Even though move constructors can make copying inexpensive, they still involve more overhead than using a const reference.
- Use pre-increment (++i) or pre-decrement (--i) operators rather than the postfix versions. This usually has no utility for simple types such as integers but may do so for complex types with a custom increment operator. Getting into a habit of writing ++i rather than i++ is good practice unless post-increment is actually the desired behavior. Apart from performance benefits, such code declares the intent more clearly by using the right operator.
- Declare variables as...