Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Strawberry: Both IO and global match are VERY SLOW. Unless pre-heated (but why?)
by syphilis (Archbishop) on Nov 14, 2023 at 00:38 UTC | |
Re: Strawberry: Both IO and global match are VERY SLOW. Unless pre-heated (but why?)
by Discipulus (Canon) on Nov 21, 2023 at 12:39 UTC | |
by Discipulus (Canon) on Dec 05, 2023 at 09:35 UTC | |
Re: Strawberry: Both IO and global match are VERY SLOW. Unless pre-heated (but why?)
by Discipulus (Canon) on Nov 14, 2023 at 08:47 UTC | |
Re: Strawberry: Both IO and global match are VERY SLOW. Unless pre-heated (but why?)
by tonyc (Friar) on Dec 04, 2023 at 22:40 UTC |