Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #74650] perlperf.pod wrong example

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

Apr 25, 2010, 6:21 AM

Post #1 of 3 (174 views)
Permalink
[perl #74650] perlperf.pod wrong example

# New Ticket Created by Daniel Pfeiffer
# Please include the string: [perl #74650]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=74650 >


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};
},
});

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

--
lerne / learn / apprends / lär dig / ucz się Esperanto:
http://lernu.net / http://ikurso.net


occitan at t-online

Aug 11, 2013, 8:26 AM

Post #2 of 3 (10 views)
Permalink
Re: [perl #74650] perlperf.pod wrong example [In reply to]

la 2013-08-11 06:26 James E Keenan via RT skribis:
> I have to admit that I'm not comfortable being asked to edit a patch
> originally submitted more than three years ago. I think we need additional
> eyeballs on Daniel's original critique of pod/perlperf.pod. Is the code
> example incorrect? If so, how do we improve it? Thank you very much. Jim Keenan

Ok, I wondered about the join slice variant, so I've added it, but it performs
about as badly (once faster, twice slower) as the wrong code in perlperf.
I've also had to bump it to 10 million, to take modern computing power into
account.

My criticism was and still is that the shown test doesn't test what it
pretends to. It talks about dereferencing strategies, but then shows a far
bigger performance loss, which instead comes from copying the 2 strings to
my-variables. That has nothing to do with the announced measurement, and
completely distorts it! Therefore I labelled it wrong and want it out of the doc.

And I have the three-element variants for comparison. Because the whole test
is about a tradeoff between an extra copying operation versus dereferencing
for each access. As tradeoffs go, they depend heavily on the proportion.
When there are two accesses, the extra copy outweighs by about 3%, but at
three accesses it is already break even. That's because the extra copy is
constantly done once.

안녕히 계세요 / coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer

--
배운다 / lerne / learn / apprends Esperanto:
http://lernu.net / http://ikurso.net
Reliability, Perl programming and much more in Makefiles:
http://makepp.sourceforge.net
Attachments: timetest.pl (1.14 KB)
  signature.asc (0.54 KB)


richard.foley at rfi

Aug 12, 2013, 2:08 AM

Post #3 of 3 (6 views)
Permalink
Re: [perl #74650] perlperf.pod wrong example [In reply to]

It's good to see this being looked at, and updated appropriately. Good job.

--
Ciao

Richard Foley

http://www.rfi.net/books.html

On Sun, Aug 11, 2013 at 05:26:28PM +0200, Daniel Pfeiffer wrote:
> la 2013-08-11 06:26 James E Keenan via RT skribis:
> > I have to admit that I'm not comfortable being asked to edit a patch
> > originally submitted more than three years ago. I think we need additional
> > eyeballs on Daniel's original critique of pod/perlperf.pod. Is the code
> > example incorrect? If so, how do we improve it? Thank you very much. Jim Keenan
>
> Ok, I wondered about the join slice variant, so I've added it, but it performs
> about as badly (once faster, twice slower) as the wrong code in perlperf.
> I've also had to bump it to 10 million, to take modern computing power into
> account.
>
> My criticism was and still is that the shown test doesn't test what it
> pretends to. It talks about dereferencing strategies, but then shows a far
> bigger performance loss, which instead comes from copying the 2 strings to
> my-variables. That has nothing to do with the announced measurement, and
> completely distorts it! Therefore I labelled it wrong and want it out of the doc.
>
> And I have the three-element variants for comparison. Because the whole test
> is about a tradeoff between an extra copying operation versus dereferencing
> for each access. As tradeoffs go, they depend heavily on the proportion.
> When there are two accesses, the extra copy outweighs by about 3%, but at
> three accesses it is already break even. That's because the extra copy is
> constantly done once.
>
> 안녕히 계세요 / coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
> Daniel Pfeiffer
>
> --
> 배운다 / lerne / learn / apprends Esperanto:
> http://lernu.net / http://ikurso.net
> Reliability, Perl programming and much more in Makefiles:
> http://makepp.sourceforge.net
>

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.