Due to some cleanup in the grid handling code, I wondered what would be faster, in terms of performance, between function templates and regular functions.
The numbers speak for their self. Function templates are way faster in this particular case.
ReleaseCand mode: template_time duration: 0.236013 regular_time duration: 0.52903
The semantics between those two tests are identical, where one is using regular functions and the other function templates. The tests iterate through 30 million random vectors (but identical in both tests).
The method signatures look like this:
// Function template template<size_t XS, size_t YS, size_t ZS> MONSTERINLINE GridPosition toGridDim( const GlobalCoords &v ); // Regular function MONSTERINLINE GridPosition toGridDim( const GlobalCoords &v, const Dimension &dimension );
The size of the grid is a compile time constant, and the compiler has the chance to optimize the regular method the same way as the function template. I haven’t tested this on Linux with gcc/g++, so it might be quirk with the VS2010 C++ compiler.
In the real world there is no difference, given the following time per invocation:
No one will notice the difference between 7 nanoseconds or 17 nanoseconds.
One nanosecond is mighty short: https://en.wikipedia.org/wiki/Nanosecond
You must be logged in to post a comment.
Be the first to comment.