#! /usr/bin/perl # Used a 78MB file for test... use Benchmark; $infile = "lala.txt"; $outfile1 = "alal_stdio.txt"; $outfile2 = "alal_sys.txt"; $t0 = new Benchmark; iotest1(); $t1 = new Benchmark; print "the stdio code took:",(timestr timediff($t1,$t0)),"\n"; $t0 = new Benchmark; iotest2(); $t1 = new Benchmark; $td = print "the sysread code took:",(timestr timediff($t1,$t0)),"\n"; sub iotest2 { open(IN,"< $infile"); open(OUT,"> $outfile2"); $buff = undef; while (sysread(IN,$in,8192)) { # This whole section could be redone...just soooo sleepy. # Only able to think in a linear fashion atm. @in = split /\n/,$buff.$in; $buff = pop @in; if ($in =~ /\n$/io) { $buff .= "\n"; } $out = join "\n",@in; # Do your thing.... chomp($out); print OUT $out."\n"; } print OUT $buff; } sub iotest1 { open(IN,"< $infile"); open(OUT,"> $outfile1"); while ($in = ) { # do whatever.... print OUT $in; } } # END Script OUTPUT generally like: the sysread code took:11 wallclock secs (10.52 usr + 0.57 sys = 11.09 CPU) the stdio code took: 5 wallclock secs ( 4.45 usr + 0.89 sys = 5.34 CPU) the stdio code took:11 wallclock secs (10.42 usr + 0.62 sys = 11.04 CPU) the sysread code took: 5 wallclock secs ( 4.62 usr + 0.73 sys = 5.35 CPU)