I had planned to write an entire new article about this, but decided this would suffice.
GCC 4.3+ is much better at optimizing tail recursion than 4.2 (which I used for my tests). GCC 4.2 was not able to optimize your version. On a side note, I'm not entirely sure that this operation is safe, in your version:
return (*begin++) + sum(begin, end);
Because I'm not sure if the order of evaluation is guaranteed by the standard. Maybe someone else can comment on that.
I think it's safe to say that the idea that "you cannot affect the performance of an optimized loop" is still alive and well. All of the numbers timings are so close to each other, that they are virtually indistinguishable.
Recent comments
10 sec ago
2 hours 55 min ago
2 hours 55 min ago
13 hours 9 min ago
14 hours 37 min ago
14 hours 37 min ago
14 hours 37 min ago
21 hours 54 min ago
2 weeks 3 days ago
4 weeks 4 days ago