Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why is my program so slow even though I've used hashes?

by DStaal (Chaplain)
on May 28, 2009 at 17:13 UTC ( [id://766705]=note: print w/replies, xml ) Need Help??


in reply to Why is my program so slow even though I've used hashes?

In addition to what everyone else has said: Whenever you hear/think/say 'why is my code slow', profile!

Replies are listed 'Best First'.
Re^2: Why is my program so slow even though I've used hashes?
by ikegami (Patriarch) on May 28, 2009 at 17:42 UTC

    Given the simplicity of the program (two nested loops), profiling won't tell you much ("the nested content is slow") until you've done some high-level analysis.

    If the nested loops can be eliminated or sped up, improvements will ensue. For example, if it's possible for $domain to have the same value for two rows of DOMFILE, a file is being read more often than it needs to be.

    And then there's the three-deep loop at the bottom. Efforts should be placed into flattening those.

    Once that's done, profiling could be used to do some micro-optimisations.

    Update: That one part of the program is IO-bound and the other is CPU-bound is noteworthy. Maybe parallelisation is an option.

      I'm of the opinion that the added understanding gained by profiling is worth it even in simple cases. At the point where you are trying to speed it up, even educated guessing is often wrong. And Devel::NYTProf (which I linked to above) does both line-level and block-level profiling, so it would directly say that the problem is that you are running these loops too often. (Leading the optimizer to start looking for ways to run them less, hopefully.)

      When looking at profile output, there is a temptation to focus on individual lines I'll admit; but it can and does help just as much on a broader scale, as long as the programmer resists that temptation.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found