develooper Front page | perl.perl5.porters | Postings from July 2021

Quadratic time constant folding

Thread Next
Ovid via perl5-porters
July 20, 2021 16:28
Quadratic time constant folding
Message ID:
In case it was missed here, Aristotle posted to BPO about quadratic time constant folding: To be fair, his post was a bit obscure in that he never quite said what he was talking about, but he linked to another blog entry discussing quadratic time constant folding in other languages and how to fix it:
This is the example Aristotle provided:

use Benchmark::Dumb 'cmpthese';

( $bar, $quux ) = qw( bar quux );

cmpthese( 0.0002, {
  conc => q{
    my $str = "xxx ";
    (((( $str .= "foo" ).= $::bar ).= "baz" ).= $::quux ).= "qux";
  intp => q{
    my $str = "xxx ";
    $str .= "foo${::bar}baz${::quux}qux";
} );
This is the output:
        Rate/s Precision/s     intp   conc
intp 5.416e+06       19000       -- -40.5%
conc 9.097e+06       53000 68+-1.1%     --
If you prefer, I converted that to the standard Benchmark module and did 10 million iterations:
          Rate intp conc
intp 4000000/s   -- -46%
conc 7407407/s  85%   --
(If it wasn't immediately clear, those two snippets assign the same value to $str)

I don't think there's an issue here, but I thought it was worth mentioning.

-- IT consulting, training, specializing in Perl, databases, and agile development 
Buy my book! -
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About