Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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)

In reply to Re: Performance Question by roboslug
in thread Performance Question by Jarinn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (4)
    As of 2020-03-29 06:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (169 votes). Check out past polls.

      Notices?