Guidelines for C++ template-based micro-optimization
- Start with the lowest level, most frequently executed code first.
- Having chosen a fixed set of data types, implement the code in assembly.
- Reimplement the code in plain C, not using any abstract data types, so that it compiles into the same assembly instructions.
- Repeat steps 2 and 3 with a few different sets of data types.
- Take all of the C code from steps 2 and 4, and reimplement using C++ templates. Determine the template arguments.
- Identify all of the non-type-based validations needed by the template function.
- Identify all of the type-based validations needed by the template function.
- Package the template function into a class template method, and implement the non-type-based validations as its methods.