use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; my $x = 'a' x 1e6; my $y = 'b' . $x; my $t = time; $x =~ s/./$&-/g; say time - $t; $t = time; $y =~ s/./$&-/g; say time - $t; say $^V; __END__ 12.7103209495544 0.850119113922119 v5.32.1 12.7171239852905 0.765337944030762 v5.28.2 0.345196962356567 0.314804077148438 v5.26.3
I didn't try latest (are they still beta?) versions, was this issue fixed? Online tests (Perl on Linux, of course) don't exhibit any anomaly. Looks like at some time after 5.26 version something weird happened to Strawberry Perl. Hard to imagine just _what_ can be happening for 10+ seconds with such relatively short string, 1 core fully loaded. And why for the 1st time only.
I understand s/.\K/-/g is better (no speed anomaly if written as such), it's not the question.
In reply to Substitution unexpectedly very slow, in Strawberry by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |