As an example of not using inline functions, in my eval, I was using a structure similar to this:
Code: Select all
inline int NegateIfBlack(Color color, int value) {
return color == WHITE ? value : -value;
}
template<Color color>
inline int eval() {
result += NegateIfBlack(color, ...);
result += NegateIfBlack(color, ...);
}
Turns out the silly optimizer decided that NegateIfBlack was not inlineable, even though the argument is a constant deduced by the template specifier. Did a profile, and NegateIfBlack was 2% of my execution time!
I ended up turning it into:
Code: Select all
template<Color color>
inline int NegateIfBlack(int value) {
return color == WHITE ? value : -value;
}
and got my nice 2% speedup (which is not huge, but enough 2% speed-ups, and you have a pretty fast program
). Of course, it's not a great example, as I was still able to use an inline and get the speed I wanted, but if the compiler isn't good enough, macros may win the day.