Jonathan,

Besides the rewriting issue there are some other optimizations possible.

Rule 1 of optimization: Don't do it. If this is a nightly backup job: Who cares about run time?

Something seems to be wrong with your file organization. Your single directory has at least 3500 files and still needs picking out text files. What kind of mess is this?

Don't reinvent the wheel. Assuming a clean directory structure:  system("$commandline_packer $options $source_dir $zipfile"). Or even leave file globbing to the command interpreter: system("$commandline_packer $options *.txt $zipfile"). Estimated speed increase: Factor 3 to 10. 7-Zip is the GPL successor to Winzip on my system. This optimization is how it was done for ages.

Assuming many short text files the most time will be spent by disk seeks. During that time the CPU is idle. Using two threads the previous file can be compressed during seek and read of another.

At the numbers as large as you have, it even might pay out to help the OS in reducing disk seeks. The idea is to create your file list, stat() it (needs to be done anyway implicitely) and sort by inode. Only then start reading. Assuming a more or less continous mapping between inode and physical disk location you reduced the number of disk seeks to a minimum. Sometimes you are able to hear and see this optimization. I'm not sure whether stat() has inode numbers on Windows. It did not on my outddated ActiveState Perl version.

Archive::Zip is much more usefull if the files have been munged by perl before compression. TMTOWTDI.


In reply to Re: Archive::Zip performance question by NiJo
in thread Archive::Zip performance question by Anonymous Monk

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.