Jump to content

Would mysql_fetch_assoc be faster than mysql_fetch_array


cooldude832

Recommended Posts

I think they're both the same. I don't think it returns those (returns array or false), it just allows you to index them that way. I can be wrong.

 

Plus, like a second really matters that much. It's like the time it takes to blink an eye. The time difference is not something that you would notice.

Link to comment
Share on other sites

i believe assoc is faster because array prints more characters than assoc think about it..

not sure but that is my opinion

But in human time and computer clock time, I don't think there is a difference unless you have a test on a very huge array. I have no idea. But these are servers. They are fast!

Link to comment
Share on other sites

but the issue is which is fast no matter how small the difference is.  and i believe printing additional character ads additional time so if you will have 10000 characters thee will be an additional 10000 characters on array and less 10000 character on assoc. well this is all a guess but i believe this is how it goes

Link to comment
Share on other sites

The question was which is faster to run, printing the results with print_r() is something entirely different. I have always assumed that mysql_fetch_assoc() would be faster and/or less memory intensive because it has less data to index, so I have always used it.

 

However, just because it "takes less than a second" is not a valid argument. What about if you have 1,000 people accessing the same page at the same time - ot 10,000. Writing tight, efficient code allows you to scale your applications much more than sloppy, inefficient code.

 

I did a quick test which seems to confirm that mysql_fetch_assoc() is indeed faster. I ran the same query twice and then created a loop on each using the two commands mysql_fetch_array() and mysql_fetch_assoc(). I did not execute any code within these loops - just one line with a comment. There were ~1,500 records in the result set and the mysql_fetch_assoc() took about 1/1000 of a second less time to complete. It doesn't sound like much, but if you consider it only took about 4/1000 seconds to complete it was 25% faster. Of course this was a very limited test so your actual milage will vary.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.