Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^5: Substitution unexpectedly very slow, in Strawberry

by swl (Parson)
on Aug 07, 2023 at 08:20 UTC ( #11153756=note: print w/replies, xml ) Need Help??


in reply to Re^4: Substitution unexpectedly very slow, in Strawberry
in thread Substitution unexpectedly very slow, in Strawberry

There seems not to be a threshold value at which it kicks in. This suggests it's not COW related?.

Modifying the code to take an argument to use as a power of 2 gives these results on Strawberry Perl 5.38. Code is below inside readmore tags.

A doubling of the n leads to a more than doubling of the time on my machine. One would need to run it many times to be confident in the true rate of change but these numbers are close to a linear relationship when plotted with time log scaled. (For those interested in such things, the power function fitted using MS Excel is t = 8E-28**(n*21.743).)

Edit: n in this case is the argument to the script, so the x-axis is n, not 2**n.

Edit 2: And a polynomial function gives a better fit when using actual number of repetitions: t = 2E-11*n**2 - 5E-06*n + 0.387, with R^2 = 0.9989 (indicative-only given the sample size).

C:\user\perlmonks>perl 11153747.pl 15 32768 0.0403292179107666 0.0388741493225098 v5.38.0 C:\user\perlmonks>perl 11153747.pl 16 65536 0.0916790962219238 0.0764880180358887 v5.38.0 C:\user\perlmonks>perl 11153747.pl 17 131072 0.361366987228394 0.142138957977295 v5.38.0 C:\user\perlmonks>perl 11153747.pl 18 262144 1.22035908699036 0.37365198135376 v5.38.0 C:\user\perlmonks>perl 11153747.pl 19 524288 4.05149698257446 0.628846883773804 v5.38.0 C:\user\perlmonks>perl 11153747.pl 20 1048576 21.3440728187561 3.00999999046326 v5.38.0

Code:

use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; my $n = 2**$ARGV[0]; say $n; my $x = 'a' x ($n-1); my $y = 'b' . $x; my $t = time; $x =~ s/./$&-/g; say time - $t; $t = time; $y =~ s/./$&-/g; say time - $t; say $^V; __END__

Replies are listed 'Best First'.
Re^6: Substitution unexpectedly very slow, in Strawberry
by syphilis (Archbishop) on Aug 07, 2023 at 13:57 UTC
    This suggests it's not COW related?

    Well, it's certainly not related to the introduction of the new COW in perl-5.20.0.
    I've just fired up my old windows 7 machine that has all of the ".0" stable releases from 5.10.0.
    The demo script ran fine from 5.18 to 5.26.0 - I didn't test back any further back than 5.18.0.
    The slowdown comes with perl-5.28.0, and then persists right up to (and including) perl-5.36.0 - which is the latest perl version on that machine.
    A quick browse of the perl5280delta didn't really sound any alarms, though I noticed the following:
    [CVE-2017-12814] $ENV{$key} stack buffer overflow on Windows A possible stack buffer overflow in the %ENV code on Windows has b +een fixed by removing the buffer completely since it was superfluous a +nyway. [GH #16051] <https://github.com/Perl/perl5/issues/16051>
    Is there possibly anything suspicious in that ? (It was the fact that it involves the removal of a buffer that led me to wonder ...)

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2023-12-06 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (31 votes). Check out past polls.

    Notices?