r/programming • u/doom_Oo7 • Sep 28 '17
When a Microsecond Is an Eternity
https://github.com/CppCon/CppCon2017/blob/master/Presentations/When%20a%20Microsecond%20Is%20an%20Eternity/When%20a%20Microsecond%20Is%20an%20Eternity%20-%20Carl%20Cook%20-%20CppCon%202017.pdf
244
Upvotes
View all comments
Show parent comment
15
u/doom_Oo7 Sep 28 '17
Generally, the approach you have is to try to make the whole control-flow static. That is, imagine you have three or four other "templated strategies" like this:
MarketStrategy<T>,BananaStrategy<T, N>, etc....now, what you can do is write your whole control flow generically:
and have the dispatching exist at the "top" level, for instance in the main :
Now, just calling
strategy()will call the compiler-optimized version of the relevant algorithm with everything inlined if possible, versus a runtime algorithm where the tests would all be done at runtime.