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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.