develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #74650] Re: perlperf.pod wrong example

Thread Previous
From:
James E Keenan via RT
Date:
August 10, 2013 01:36
Subject:
[perl #74650] Re: perlperf.pod wrong example
Message ID:
rt-3.6.HEAD-2552-1376098598-356.74650-15-0@perl.org
On Sun Apr 25 06:21:03 2010, occitan@esperanto.org wrote:
> In the dereference benchmark you make exactly the mistake you warn of 
> before: you change several factors at once and show an overdrawn 
> conclusion.  While refactoring out the common $ref->{ref} to access it 
> only once, you unnecessarily also copy both strings to a local 
> variable.  It is this second action that drives the time up, if you 
> leave that out and run timethese several times your findings are still 
> right, but far less.  If however you need a third or more values (which 
> I added of the same length), dereferencing the outer hash only once 
> becomes a clear winner:
> 
>     timethese(1000000, {
>         '2direct'      => sub {
>             my $x = $ref->{ref}{_myscore} . $ref->{ref}{_yourscore} ;
>         },
>         '2wrong'       => sub {
>             my $ref = $ref->{ref};
>             my $myscore = $ref->{_myscore};        # why?
>             my $yourscore = $ref->{_yourscore};    # why?
>             my $x = $myscore . $yourscore;
>         },
>         '2dereference' => sub {
>             my $ref = $ref->{ref};
>             my $x = $ref->{_myscore} . $ref->{_yourscore};
>         },
>         '3direct'      => sub {
>             my $x = $ref->{ref}{_myscore} . $ref->{ref}{_yourscore} .
>                 $ref->{ref}{_ourscore};
>         },
>         '3dereference' => sub {
>             my $ref = $ref->{ref};
>             my $x = $ref->{_myscore} . $ref->{_yourscore} .
>                 $ref->{_ourscore};

I get "Use of uninitialized value in concatenation (.) or string" on the
line above.

>         },
>     });
> 
> Btw. I have left out the intermediate arrow, making it less of an 
> eyesore and easier to understand as a two dimensional hash.
> 
> coralament / best Gr�tens / liebe Gr��e / best regards / elkorajn salutojn
> Daniel Pfeiffer
> 


Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=74650

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About