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 |