Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Script Executes Very Slowly

by Old_Gray_Bear (Bishop)
on Aug 04, 2014 at 19:25 UTC ( [id://1096192]=note: print w/replies, xml ) Need Help??


in reply to Script Executes Very Slowly

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.

----
I Go Back to Sleep, Now.

OGB

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1096192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found