LA.pm: Efficiency

Douglas Wilson dgwilson at gtemail.net
Sat Oct 27 10:54:32 CDT 2001


Try something like:

use Benchmark qw(cmpthese);
use DBI;

DBI->connect(..., {RaiseError=>1});
my $sql1 = "select 1 from table";
my $sql2 = "select count(*) from table";

my $sth1 = $dbh->prepare($sql1);
my $sth2 = $dbh->prepare($sql2);
my $cnt;

# Pick a sufficiently large negative number
cmpthese(-10, {
 FETCHALL=>sub {
  $sth1->execute;
 ++$cnt while $sth1->fetch;
 },
 CNT=>sub {
  $sth2->execute;
  $cnt = $dbh->selectrow_array($sth2);
 }
});

Even this can be a meaningless test due to disk or database
caching, etc...

-Doug
-----Original Message-----
From: Arkadiy Sudarikov <asudarikov at xceed.com>
Date: Fri, 26 Oct 2001 23:31:48 -0500
To: "'LA.pm'" <list at la.pm.org>
Subject: LA.pm: Efficiency


> I Benchmarked { SELECT COUNT(*) } and { SELECT * and $count++ while fetch }
> and got same times... Now, what does that mean? Shouldn't one be "better"
> than the other?
> 
> 

-- 

_______________________________________________
Talk More, Pay Less with Net2Phone Direct(R), up to 1500 minutes free! 
http://www.net2phone.com/cgi-bin/link.cgi?143 






More information about the Losangeles-pm mailing list