Reply to comment

Not All GCC's Are Create Equally

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.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.