Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Performance Question

by roboslug (Sexton)
on May 08, 2002 at 16:38 UTC ( #165092=note: print w/replies, xml ) Need Help??

in reply to Performance Question

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)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://165092]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2020-04-10 07:07 GMT
Find Nodes?
    Voting Booth?
    The most amusing oxymoron is:

    Results (49 votes). Check out past polls.