Welcome to the Monastery | |
PerlMonks |
Re: Script Executes Very Slowlyby Old_Gray_Bear (Bishop) |
on Aug 04, 2014 at 19:25 UTC ( [id://1096192]=note: print w/replies, xml ) | Need Help?? |
Well, my first thought was "This is a job for the NYT Profiler. Then I took a look at the code.
You say there are 200 name-title combinations in @flab and 72,000 lines in the match file. That means that you are executing your foreach loop 1.4 MILLION times (7200 lines x 200 comparisons). Rewrite your code. Put the 200 entries into a hash keyed by "$name---$title". Then the entire loop collapses in to a single hash-lookup after extracting the fields and building the key. If you don't want to do such a major restructuring, at least insert last after you print the results. Once you have found the name, you don't need to check any further. Over a large number of searches this will reduce your search time by roughly half. (Making assumptions about normally distributed data, so your results may vary.) Note: This assumes that the 'name' fields are unique. If there can be multiple 'title's attached to the same 'name' you really do have to search the entire @flab array for each line. Sigh.
---- OGB
In Section
Seekers of Perl Wisdom
|
|