I'm having issues. You're telling me that the cost of calling a subroutine that returns a $dbh is overshadowing both the cost of creating the $dbh as well as the cost of whatever you're doing with that $dbh? That's not passing the sniff test.
In general, I find that optimizing the database provides a benefit/cost1 that's at least 10x greater than any Perl optimization. For example, if you have something like:
my $sth = $dbh->prepare_cached("SELECT foo,bar from table where id = ?
+");
for my $id (@ids) {
$sth->execute( $id );
my @results = $sth->fetchrow_array;
$sth->finish;
}
You'll gain a significant speedup rewriting it to:
my $placeholders = join ',', ('?') x @ids;
my $sth = $dbh->prepare_cached(
"SELECT id,foo,bar from table where id IN ($placeholders)",
);
$sth->execute( @ids );
$sth->bind_columns( \my ($id, $foo, $bar ) );
while ( $sth->fetch ) {
# Put values somewhere
}
$sth->finish;
That's both taking advantage of the best way to handle DBI as well as allowing the database to do more of the work. And, there's hundreds of similar restructurings that can provide up to 90% gains. The database will almost always be a major limiter of performance, especially if you're not doing it smart.
- benefit/cost == The amount gained divided by (effort taken + effort to maintain). So, for example, if you were to replace all calls to a subroutine with the body of the subroutine, there would be a significant cost to do it (search+replace can do it, but testing's a bitch) plus a significant increase in maintenance (any change has to be applied with search+replace).
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.