Greetings. I would describe myself as an intermediate Perl coder, although I am sure that is subject to much interpretation. Anyhow, my question is one of optimization.

The scenario: I have quite a few (up to around 100) large text files (400K-800K). Each contains time series data organized by row. The job is to find matching "types" of lines across the files and then calculate averages of their data columns and put them in an output file.

The process that I have in place now goes like this:
  1. Bring all of the files into memory as arrays within one central organizing array.
    i.e. $results[$rep] = [<RESULTS>];
  2. Look at line 0 of file 0 and find entries in each of the other files that match the time step and type columns.
  3. When you have the list of lines, calculate the average of their data columns and output these results to a file
  4. Remove these lines from their arrays (splice)
  5. Move onto line 1 of file 0
  6. Lather, rinse & repeat

This only works because I haven't been testing with very many of these text files (I've only been bringing about 6 into memory at a time - and even this is quite arduous).

What I would like to have is some sort of streaming file reader. That way I could stream through each of the 100 files in parallel, calculating averages as I go. This would all but eliminate the time it takes to drag these files into memory to be worked on, as well as reduce the memory footprint of the process.

The question is, how can I stream through many files in parallel when their structures aren't exactly parallel (some files have different time step sequences, or different "type" lines within a given time step)?

Also, as an aside, is the Benchmark module the standard tool to time code?


In reply to Tabulating Data Across Multiple Large Files by reds

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.