C:\test>215578 -BUFN=16 pipes.dat 1 trial of sysread (160.090s total) 1 trial of sysread2 (182.623s total) 1 trial of stdio (324.950s total) sysread:20000 sysread2:20000 stdio:20000 #### #! perl -slw use strict; use Benchmark::Timer; use vars qw[$BUFN]; $BUFN ||= 1; # Buffer size in steps of 4096 bytes. my $t=Benchmark::Timer->new(); my $re_fields = qr[ ([^|]+)\| # Capture field 0 (?:[^|]+\|){2} # Skip 1 .. 2 ([^|]+)\| # Capture 3 .. 4 ([^|]+)\| (?:[^|]+\|){4} # Skip 5..8 ([^|]+)\| # Capture 9 (?:[^|]+\|){7} # Skip 10..16 ([^|]+)\| # Capture 17..18 ([^|]+)\| (?:[^|]+\|){11} # Skip 19..30 ([^|\n]+) # Capture 31 \n # Discard the newline ]ox; my $buffer = ""; $t->start('sysread'); open my $in, $ARGV[0] or die "Couldn't open $ARGV[0]:$!"; my %h1; while (sysread($in, $buffer, 4096*$BUFN, length $buffer)) { while($buffer =~ m[$re_fields]mog ) { # << Regex. $h1{$_}++ for ($1,$2,$3,$4,$5,$6,$7); } $buffer = substr($buffer, 1+rindex($buffer, "\n")); } close $in; $t->stop('sysread'); $t->start('sysread2'); open $in, $ARGV[0] or die "Couldn't open $ARGV[0]:$!"; my %h2; while (sysread($in, $buffer, 4096*$BUFN, length $buffer)) { my ($p1, $p2) = (0) x 2; while ($p2 = 1 + index($buffer, "\n", $p1)) { $h2{$_}++ for substr($buffer, $p1, $p2 - $p1) =~ $re_fields; # << Regex. $p1 = $p2; } $buffer = substr($buffer, 1+rindex($buffer, "\n")); } close $in; $t->stop('sysread2'); my %h3; $t->start('perlio'); open $in, $ARGV[0] or die "Couldn't open $ARGV[0]:$!"; while(<$in>){ my @fields = split'[\|\n]'; $h3{$_}++ for @fields[0,3,4,9,17,18,30]; } close $in; $t->stop('stdio'); $t->report; print 'sysread:', scalar keys %h1, ' sysread2:', scalar keys %h2, ' stdio:', scalar keys %h3; $h1{$_} ne $h3{$_} and print "$h1{$_} ne $h3{$_}" for keys %h3; $h2{$_} ne $h3{$_} and print "$h2{$_} ne $h3{$_}" for keys %h3; __END__ C:\test>215578 -BUFN=16 pipes.dat 1 trial of sysread (160.090s total) 1 trial of sysread2 (182.623s total) 1 trial of stdio (324.950s total) sysread:20000 sysread2:20000 perlio:20000