Your inerrant holiness who represents all of us!

> Indeed, whatever alternative mechanism is used, in whatever language, it will always be more costly than the natural return chain. The stack still has to be unwound

> Just as the exception mechanism in C++ (or structured exceptions in MSC), are a magnitude or more expensive because they have to search back up the stack looking for stack frames interpreting them as they go; so the goto that underlies such mechanisms in Perl has to go through an equally convoluted process to find a label at the appropriate scope.

Some heretics didn't fully trust you and tried to measure a time penalty for die or goto.

Look what they have done!

Timing for 1000000 recursions: Mode: return takes sec: 5.55880403518677 Mode: goto takes sec: 4.51015114784241 Mode: die takes sec: 1.70386385917664

use Time::HiRes qw/time/; no warnings 'recursion'; our $mode; sub rec { my $i=shift; $i--; if ($i<0) { return if $mode eq "return"; goto OUT if $mode eq "goto"; die "finished" if $mode eq "die"; } rec($i) } $|=1; my $recs=1000000; print "Timing for $recs recursions:\n" ; for $mode (qw/return goto die/) { print "\tMode: $mode takes sec: "; my $start=time; eval { rec($recs); }; OUT: # print $@ if $@; print time-$start,"\n"; }

Please prove them wrong!

May those heathens all burn in hell (...or emacs)!

Cheers Rolf

( addicted to the Perl Programming Language)


In reply to Re^4: Continuations in Perl - Returning to an arbitrary level up the call stack by LanX
in thread Continuations in Perl - Returning to an arbitrary level up the call stack by unlinker

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.