in reply to best way to inline code? (i.e. macro)
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:
You'll gain a significant speedup rewriting it to: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; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: best way to inline code? (i.e. macro)
by SheridanCat (Pilgrim) on Oct 18, 2005 at 14:47 UTC |