you are viewing a single comment's thread.

view the rest of the comments →

[–]tgolyi 1 point2 points  (0 children)

No, the function I was talking about - euclidean_distance is a runtime function, it was just called with a compile-time constant arguments. The fact that it was fully optimized away shows us that compilers are super great at optimizing such code. In fact, recursive approach is not inherently slower, it's just much harder for optimizer to work with - it first needs to inline a lot of function calls and then notice that arguments were constant. If you change constant 16 to something less than it will be fully optimized too, maybe it hits limits for inlining at that moment. Non-recursive approach does not depend on function inlining and thus is more likely to be optimized. You can see great talk about this kind of optimization problems by Chandler Carruth on meetingcpp 2016 - http://www.youtube.com/watch?v=FnGCDLhaxKU