Depending on your database, it might be more efficient for you to push as much of the grouping and comparisons to the database engine. I can't tell what could be done because your question is pretty vague with regard to the nature of the 'analysis' that you are performing.

If the number of groupings is fairly small, you might consider building result set hashes or arrays for each grouping, so that (for a particular entry with a particular grouping code) you could only visit the result sets that do NOT correspond to the entry's grouping code (as you specified).

Instinctively, I flinch when I see an Order n-squared algorithm -- it seems like there might be a better way to skin this cat, but again, I'm not able to give you advice on this at this level of abstraction, except to say that if you find yourself executing the same database query over and over again, you can sometimes save quite a bit of time building a lookup hash once with a slightly more complex query, and then referring to that hash instead of going to the database over and over.

Of course, you'll want to build statement handles and placeholders for any repetitive query.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

In reply to Re: an efficient program? by ptum
in thread an efficient program? by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.