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", ( )[ $method ], ( $preheat ? 'pre-heat' : 'no pre-heat' ), time - $t } #### 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