Wow, I'm impressed.

An idealized benchmark shows only a 25% gain by memoizing, so I agree, it doesn't worth it.

Rate classic memoized classic 75415/s -- -19% memoized 93110/s 23% --
use strict; my $obj={}; bless $obj,"Class"; sub classic { $obj->meth0->meth1->meth2->meth3->meth4->meth5->meth6->meth7->meth8- +>meth9; } my $ref0=$obj->can("meth0"); my $ref1=$obj->can("meth1"); my $ref2=$obj->can("meth2"); my $ref3=$obj->can("meth3"); my $ref4=$obj->can("meth4"); my $ref5=$obj->can("meth5"); my $ref6=$obj->can("meth6"); my $ref7=$obj->can("meth7"); my $ref8=$obj->can("meth8"); my $ref9=$obj->can("meth9"); sub memoized { $obj->$ref0->$ref1->$ref2->$ref3->$ref4->$ref5->$ref6->$ref7->$ref8- +>$ref9; } use Benchmark qw/cmpthese/; cmpthese(1E6, { classic => \&classic, memoized => \&memoized, }); package Class; sub meth0 { $_[0] } sub meth1 { $_[0] } sub meth2 { $_[0] } sub meth3 { $_[0] } sub meth4 { $_[0] } sub meth5 { $_[0] } sub meth6 { $_[0] } sub meth7 { $_[0] } sub meth8 { $_[0] } sub meth9 { $_[0] }

Cheers Rolf


In reply to Re^6: Error handling in chained method calls by LanX
in thread Error handling in chained method calls by szabgab

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.