You may want to try to compile your regexps before the loop with something like :

my $re1 = qr/3_prtnm_/; my $re2 = qr/2_tname_/; # ... while( <STDF> ) { # ... if( m/$re1/ ) { @tmp = split($re1); #... } elsif( m/$re2/ ) { @tmp = split($re2); #... } }

Another trick, if you have a few million lines to parse could be to rewrite the inside of the loop to something more like :

my $re = qr/(3_prtnm_|2_prtnm_|2_mrslt_)/; # ... while( my $line = <STDF> ) { if( m/$re/ ) { my $sep = $1; my @tmp = split( /$sep/, $line ); # ... } }

I'm not sure if the spedup would be noticable because of the varying split that should be benchmarked/optimized.

Have a look to http://www.stonehenge.com/merlyn/UnixReview/col28.html for regexp compilation.

One sure thing is that threading is hard to get right and in big loops there are generally many other possible optimizations to try before.


In reply to Re: How to speed up/multi thread extract from txt files? by Anonymous Monk
in thread How to speed up/multi thread extract from txt files? by MelaOS

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.