Bad benchmark. Out of the millions of passes of each sub, you only count up to 10,000 once. The only relevant result is dropped as an outlier, so you're benchmarking inc+compare+return vs loop+inc+compare+return. Of course the latter will be slower.

Also, you should probably include the naïve case.

use Benchmark qw(cmpthese); my $limit = 10_000; sub f0 { ++$_ < $limit ? &f1 : return $_ } sub f1 { ++$_ < $limit ? goto &f1 : return $_ } sub f2 {{ ++$_ < $limit ? redo : return $_ }} cmpthese -1, { f0 => sub { $_ = 0; f0() }, f1 => sub { $_ = 0; f1() }, f2 => sub { $_ = 0; f2() }, };
Rate f1 f0 f2 f1 245/s -- -15% -71% f0 288/s 18% -- -65% f2 836/s 241% 190% -- Rate f1 f0 f2 f1 212/s -- -22% -78% f0 271/s 28% -- -72% f2 954/s 350% 253% -- Rate f1 f0 f2 f1 218/s -- -23% -77% f0 283/s 30% -- -70% f2 932/s 328% 229% --

In reply to Re^2: Syntactic sugar for tail call optimizations by ikegami
in thread Syntactic sugar for tail call optimizations by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.