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 }