Re: [Phplib-users] Benchmark of Db class
Brought to you by:
nhruby,
richardarcher
From: Donncha O C. <don...@tr...> - 2001-10-26 09:27:15
|
1. Yes, he could leave out that $db->connect() call. Creating the $db object should be enough. 2. I would suspect that accessing the Record[] array directly instead of calling the f() function is slightly faster. This is the way I've always accessed the MySQL result set. 3. By using integer indexes he may save some milliseconds. I'm only guessing since text inside "quotes" is interpreted by PHP. 4. I would also question his use of $db->free() as well. I have never had to use it, and AFAIK db_mysql.inc calls the MySQL free() function when it's needed. It's outside the main while() loop so it shouldn't be too much of a slow down. I don't think he could have done much to make this query faster, and I was happy to see Phplib do so well. The fact that adodb won wasn't a surprise, but I won't discount that it may be better in certain conditions than phplib. He should have probably did a check for num_rows() to reflect more real-life situations. His code would generate the usual "0 is not a MySQL result set" or similar error message if no data was returned. Donncha. Peter Bowyer wrote: > > Hi, > > For those of you who haven't seen it yet, http://php.weblogs.com has been > benchmarking the database classes. Not surprisingly his DBA comes out > fastest (!) with PHPLib a close second. I have been looking at the source > code of the PHPLib benchmark and wondered if it could actually be speeded up? > -- PHPLib source code - full code from http://phplens.com/lens/adodb/ -- > <?php > include_once('../../php/phplib-7.2d/php/db_mysql.inc'); > $DBNAME = 'PHPLib'; > > function &Connect() > { > $db = new DB_Sql(); > $db->connect("northwind", "localhost", "root", ""); > return $db; > } > > function QueryOnce(&$db,$debug) > { > $rs = $db->query('select > productid,productname,unitsinstock,unitprice from products'); > while ($db->next_record()) { > $id=$db->Record[0]; > $name=$db->Record[1]; > $unitsinstock=$db->Record[2]; > $unitprice=$db->Record[3]; > > if ($debug) { > print "$id, $name, $unitsinstock, $unitprice<br>"; > } > } > $db->free($rs); > } > ?> > -------------------------------------------- > As I see it, he can cut out the db->connect and just put the details in the > class file. Would the latest version of db_mysql.inc from CVS make much > difference? Also, can anyone tell me what difference in performance there > is between $id=$db->Record[0]; and $id=$db->f("productid"); ?? > > Any feedback gratefully received, and if there's any changes then I'll pass > them on to John Lim. > > Cheers! > Peter. > |