LA.pm: Efficiency

Arkadiy Sudarikov asudarikov at xceed.com
Sat Oct 27 15:10:53 CDT 2001


Wow. You took the code straight from my editor :) Your code is exactly what
I wrote... 

Thanks though,
Arkadiy

-----Original Message-----
From: Douglas Wilson
To: Arkadiy Sudarikov; 'LA.pm'
Sent: 10/27/2001 10:54 AM
Subject: Re: LA.pm: Efficiency


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