Ok, confirmed sysread. Using sysread and all the goo to make it use lines takes approx half the time of reading from <>.
Been up all night working on stuff and now things are swirly (getting to old for this), so I know this code is ugly and all...but hey...
#! /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 = <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 C
+PU)
the stdio code took:11 wallclock secs (10.42 usr + 0.62 sys = 11.04 C
+PU)
the sysread code took: 5 wallclock secs ( 4.62 usr + 0.73 sys = 5.35
+ CPU)