use strict; use warnings; use DBI; use Time::HiRes qw/gettimeofday tv_interval/; my $dbh = DBI->connect or die "oops - $!\n"; print $dbh->selectrow_arrayref('select version()')->[0], "\n\n"; my $sql1 = "select * from foo"; my $sql2 = "select * from foo where 0 = 1"; print " prepare execute finish\n"; time_this( $dbh, $sql1, ' no where' ); time_this( $dbh, $sql1, ' no where' ); time_this( $dbh, $sql1, ' no where' ); print "\n"; time_this( $dbh, $sql2, 'where 0=1'); time_this( $dbh, $sql2, 'where 0=1' ); time_this( $dbh, $sql2, 'where 0=1' ); sub time_this { my ($dbh, $sql, $how) = @_; my $t0; $t0 = [gettimeofday]; my $sth = $dbh->prepare( $sql ); print $how, " "; printf(" %7.5f", tv_interval($t0 , [gettimeofday])); $t0 = [gettimeofday]; $sth->execute; printf(" %7.5f", tv_interval($t0 , [gettimeofday])); my @fld = @{$sth->{NAME}}; $t0 = [gettimeofday]; $sth->finish; printf(" %7.5f", tv_interval($t0 , [gettimeofday])); print "\n"; }