Reading data from table (performance test)

Discussion in 'PHP' started by clades, Dec 29, 2008.

  1. #1
    I just came to the conclusion that this method:

    $n = mysql_num_rows
    for($i=0;$i<$n;$i++)
    {
        mysql_data_seek($query,$i);
        manipulate row's data
    }
    Code (markup):
    is more or less 2,5x times faster than:

    while($dat = mysql_fetch)
        manipulate row's data
    Code (markup):
    The second is much easier to write but the performance is terrible, can you please confirm if i'm right?.
     
    clades, Dec 29, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
        mysql_data_seek($query,$i);
    PHP:
    Doesn't actually return any data, it just sets the point to the specified row (per se.)

    You still need to run mysql_fetch_assoc (or w/e) afterwards, it's faster to just use mysql_fetch_assoc in the first place.
     
    Danltn, Dec 29, 2008 IP
  3. clades

    clades Peon

    Messages:
    579
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The "manipulate row's data" includes the fetch +_+

    I was just trying to figure out why the while is so slow...
     
    clades, Dec 29, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    The while isn't/shouldn't be slow.
     
    Danltn, Dec 29, 2008 IP