Processing is fast. I/O is slow.

Whenever someone asks me to look at their code for speedups, we often get into this discussion. For the more obstinate, I often suggest making a "do-nothing" version of their program that just reads in (files or whatever) and writes it back out again. Run this on a sample/benchmark input. We can then argue about Big-Oh numbers, and how this do-nothing version's input/output volume compares with a real example.

Results are often along these lines: "The Do Nothing version took 5 minutes to read a bazillion records and write them out again. The real program is taking an extra 5 seconds on top of that (on average). If you really need a speedup, use faster storage media."

I've always found Perl's IO to be very fast, roughly comparable to something written in C. To check, compare a "passthrough" script like:

perl -pe '' blah.in >/dev/null

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re^2: Performance improvement by using $_ instead of named variables by QM
in thread Performance improvement by using $_ instead of named variables by solegaonkar

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, details, 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, summary, 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.