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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |