in reply to how to speed up program?
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:
You might then have discovered that making a new database connection is relatively expensive.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";
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: how to speed up program?
by Anonymous Monk on Aug 16, 2002 at 22:33 UTC |