The foreach loop is very slow (takes 2 days to run) because there are 31,197 alarms each analyzing 155 Quench Times. I wrote sub GetQuenchInfo to create a hash to try to speed up...

You made two mistakes here: First, you started optimizing within a loop before you considered what you could move out of the loop. Second, you began pursuing a particular optimization (creating a hash) before you'd gathered data on where your script was spending its time.

Making a database connection and running the queries can be moved out of the loop, since nothing they do depends on $supply, which is the only thing varying in that loop. (Is this intentional, or a bug?) But for a moment, let's pretent they can't be moved out of the loop.

Since you know the performance problem is in the loop, a reasonable approach is to pick the loop apart, looking for where the script might be spending time. Then add some simple timing code to gather data. For example:

my $aboutToConnect = time(); # start timing my $dbEvents = new Sybase::CTlib 'harmless','harmless','OPSYB1','fil +leventsT'; print "Sybase::CTlib took ", time() - $aboutToConnect, " seconds to connect\n";
You might then have discovered that making a new database connection is relatively expensive.

Ditto for timing the queries.

If you discover that 99% of your time is going to database work, then trying to improve performance by using a hash is pointless, unless reducing that 1% to 0.5% is going to pay off.


In reply to Re: how to speed up program? by dws
in thread how to speed up program? by cjacksonjr

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.