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
4 weeks 3 days ago
7 weeks 9 hours ago
7 weeks 4 days ago
8 weeks 9 hours ago
8 weeks 9 hours ago
8 weeks 9 hours ago
9 weeks 5 days ago
10 weeks 5 days ago
12 weeks 6 days ago
12 weeks 6 days ago