I don't think this is related to my previous Substitution unexpectedly very slow, in Strawberry, which GH ticket is marked as fixed. I can't check this new issue with 5.39. But if the fix also cures what's described below -- then fine. + Preliminary check with online Perl doesn't show anomalies, so looks like Linux is OK, it's Windows issue.

The recent File::Slurp discussion made me have a look at how it behaves in list context. In particular, a look at regex it uses to split, at line #133. I wondered if it's really the best method, then ran some tests. Accidentally, in the process I stumbled upon really weird results. As frustrating as it is, but close to unsellability, kind of.

I did "physical file IO", not "scalar IO", to better demonstrate how it can affect (and always did?) the very basic daily operations. "Preheat" immediately disposes of allocated array, it's not well-known "pre-set $#array or hash size for better performance".

use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; if ( !@ARGV ) { say $^V; for my $size ( 5e5, 1e6, 5e6 ) { say "Array size: $size"; for my $method ( 0, 1, 2 ) { for my $heat ( 0, 1 ) { system $^X, $0, $method, $heat, $size } } } } else { my ( $method, $preheat, $size ) = @ARGV; my $s = join ' ', 0 .. 9; $s .= "\n"; $s x= $size; chomp $s; my $t = time; if ( $preheat ) { my @garbage = ( undef ) x $size } my @a; if ( $method == 0 ) { # split @a = split /(?<=\n)/, $s } elsif ( $method == 1 ) { # global match @a = $s =~ /(.*?\n|.+)/gs } elsif ( $method == 2 ) { # IO (list context) open my $fh, '>', 'garbage.tmp'; binmode $fh; print $fh $s; close $fh; open $fh, '<', 'garbage.tmp'; binmode $fh; @a = <$fh>; close $fh; } printf "\t%s, %s:\t%.3f\n", ( <split match io(list)> )[ $method ], ( $preheat ? 'pre-heat' : 'no pre-heat' ), time - $t }

Result:

v5.38.0 Array size: 500000 split, no pre-heat: 0.627 split, pre-heat: 0.631 match, no pre-heat: 0.855 match, pre-heat: 0.292 io(list), no pre-heat: 0.893 io(list), pre-heat: 0.274 Array size: 1000000 split, no pre-heat: 1.272 split, pre-heat: 1.286 match, no pre-heat: 3.604 match, pre-heat: 0.583 io(list), no pre-heat: 3.498 io(list), pre-heat: 0.556 Array size: 5000000 split, no pre-heat: 6.356 split, pre-heat: 6.346 match, no pre-heat: 79.586 match, pre-heat: 2.885 io(list), no pre-heat: 84.150 io(list), pre-heat: 2.744

In reply to Strawberry: Both IO and global match are VERY SLOW. Unless pre-heated (but why?) 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.