Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Proxying (almost) all methods in a class for mass memoization

by choroba (Cardinal)
on Aug 16, 2018 at 10:01 UTC ( [id://1220411]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Proxying (almost) all methods in a class for mass memoization
in thread Proxying (almost) all methods in a class for mass memoization

> I would have imagined that such a thing would have been easily optimised away at compilation

And, unsurprisingly, it's been the case since 5.20!

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^4: Proxying (almost) all methods in a class for mass memoization
by davido (Cardinal) on Aug 16, 2018 at 20:24 UTC

    I wonder what it takes to trigger that optimization.

    davido:~/scripts$ perlbrew exec --with perl-5.10.1 perl mytest.pl Perl version: 5.010001 Rate retn bare retn 6849315/s -- -8% bare 7462687/s 9% -- (25000000, 25000000) davido:~/scripts$ perlbrew exec --with perl-5.28.0 perl mytest.pl Perl version: 5.028000 Rate bare retn bare 10729614/s -- -3% retn 11013216/s 3% -- (25000000, 25000000)

    I mean I do see a difference, but other optimizations between Perl 5.10 and Perl 5.28 seem to be far more significant (probably the integer optimization).

    Here is the sample code:

    use strict; use warnings; use Benchmark qw(cmpthese); my $x; my $y; sub bare { ++$x; $x } sub retn { ++$y; return $y } print "Perl version: $]\n\n"; cmpthese(25_000_000, { bare => sub {my $t = bare()}, retn => sub {my $t = retn()}, }); print "\n($x, $y)\n";

    The reason for the double sub call is to assure that the return value is being obtained, and not discarded due to context. So we do have the double-call overhead, but it's the same overhead for both sides of the test.

    Anyway, where there had been a 9% difference in favor of bare returns in 5.10, there's now a statistically insignificant 3% difference that seems to go either direction.


    Dave

Re^4: Proxying (almost) all methods in a class for mass memoization
by tobyink (Canon) on Aug 16, 2018 at 11:44 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220411]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found