>  Mysql_fetch_assoc() is faster -- use it.  I've learned something.

Using your script and postgres, with PGSQL_ASSOC in fetch_array:

fetch_assoc(): 1.62810707092 seconds [18880 rows](1066665580.0.52192900 :
1066665578.89)
fetch_array(): 1.54432892799 seconds [18880 rows](1066665582.0.06938900 :
1066665580.53)

second time:
fetch_assoc(): 1.45861208439 seconds [18880 rows](1066666481.0.87854800 :
1066666480.42)
fetch_array(): 1.46833896637 seconds [18880 rows](1066666483.0.34997600 :
1066666481.88)

Maybe fetch_assoc() is not so much faster than fetch_array()...
:) yes I have also 18880 rows

The code:
include('../include/db.php');
$sql = "select * from items";

   list($l,$r) = split(" ",microtime());
   $start = $l + $r;
   $r = pg_query($db, $sql);
   $num = pg_num_rows($r);
   while( $row = pg_fetch_assoc($r) ) {
      // echo "";
   }
   list($l, $r) = explode(" ",microtime());
   $diff = ((float)$l + (float)$r) - (float)$start;
   echo "<hr/>fetch_assoc(): $diff seconds [$num rows]($r.$l :
$start)<hr/>";

   list($l,$r) = explode(" ",microtime());
   $start = ((float)$l + (float)$r);
   $r = pg_query($db, $sql);
   $num = pg_num_rows($r);
   while( $row = pg_fetch_array($r, NULL, PGSQL_ASSOC) ) {
      // echo "";
   }
   list($l, $r) = explode(" ",microtime());
   $diff = ((float)$l + (float)$r) - (float)$start;
   echo "<hr/>fetch_array(): $diff seconds [$num rows]($r.$l :
$start)<hr/>";




----- Original Message ----- 
From: "Peter Beckman" <[EMAIL PROTECTED]>
To: "Jon Kriek" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, October 20, 2003 4:23 PM
Subject: Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in
arrays


> On Mon, 20 Oct 2003, Jon Kriek wrote:
>
> > Easier is not always "right" or "good script-logic"
> >
> > Would it be easier for you to type:
> >
> > mysql_fetch_array($result, MYSQL_ASSOC) {
>
>  OK, can we clear this up once and for all?
>
>   mysql_fetch_assoc(): 3.7182140350342 seconds [18880 rows]
>   mysql_fetch_array(): 5.769602060318 seconds [18880 rows]
>
>  Same data set in both cases.  While there isn't MUCH difference, using
>  assoc gives one a 30% increase in speed in my rudimentary test over
array.
>
>  Mysql_fetch_assoc() is faster -- use it.  I've learned something.
>
>  The code:
>    $sql = "select * from tblApplications";
>
>    list($l,$r) = split(" ",microtime());
>    $start = $l + $r;
>    $r = mysql_query($sql);
>    $num = mysql_num_rows($r);
>    while( $row = mysql_fetch_assoc($r) ) {
>       // echo "";
>    }
>    list($l, $r) = explode(" ",microtime());
>    $diff = ((float)$l + (float)$r) - (float)$start;
>    echo "<hr/>fetch_assoc(): $diff seconds [$num rows]($r.$l :
$start)<hr/>";
>
>    list($l,$r) = explode(" ",microtime());
>    $start = ((float)$l + (float)$r);
>    $r = mysql_query($sql);
>    $num = mysql_num_rows($r);
>    while( $row = mysql_fetch_array($r) ) {
>       // echo "";
>    }
>    list($l, $r) = explode(" ",microtime());
>    $diff = ((float)$l + (float)$r) - (float)$start;
>    echo "<hr/>fetch_array(): $diff seconds [$num rows]($r.$l :
$start)<hr/>";
>
> Beckman
> --------------------------------------------------------------------------
-
> Peter Beckman                                                  Internet
Guy
> [EMAIL PROTECTED]
http://www.purplecow.com/
> --------------------------------------------------------------------------
-
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to