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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |