cooldude832 Posted January 8, 2008 Share Posted January 8, 2008 When you do mysql_fetch_array it returns a indexed (0,1,2,3 etc) and Associative keys, mysql_fetch_assoc returns only associative which is faster? Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/ Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433238 Share on other sites More sharing options...
pocobueno1388 Posted January 8, 2008 Share Posted January 8, 2008 I agree, I doubt one is that much faster than the other that it would really matter. If your curious, why not just run your own tests? Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433242 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 I don't have a good testing ground because I can't isolate what is confided "network Noise" but the print_r does show the 0,1,2 and associative one Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433244 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 I don't have a good testing ground because I can't isolate what is confided "network Noise" but the print_r does show the 0,1,2 and associative one Do you know how fast computers, nay servers, run? Displaying those is like nothing to them. Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433245 Share on other sites More sharing options...
teng84 Posted January 8, 2008 Share Posted January 8, 2008 i believe assoc is faster because array prints more characters than assoc think about it.. not sure but that is my opinion Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433253 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433257 Share on other sites More sharing options...
teng84 Posted January 8, 2008 Share Posted January 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433258 Share on other sites More sharing options...
Psycho Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433284 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 You can cut corners anywhere I just wanted to provoke people Quote Link to comment https://forums.phpfreaks.com/topic/84964-would-mysql_fetch_assoc-be-faster-than-mysql_fetch_array/#findComment-433288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.