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.
|