Page 1 of 1

[solved] Two things I've always wondered.

Posted: Tue Sep 18, 2007 2:11 pm
by Mightywayne
(regarding php)

1. When choosing mysql_fetch_assoc, instead of fetch_array, how much strain do you think that saves?

2. Let's say I am fetching an entry from a table that has 10 fields in it. Would that be slower than a table that had 2 fields in it?

Posted: Tue Sep 18, 2007 2:36 pm
by Begby
It will most likely be immeasurable unless is under really heave load. Worry about these kind of things later after your applicatiton is complete, otherwise it will never get done.

Posted: Tue Sep 18, 2007 2:56 pm
by pickle
If he worries about these things after his app is built, then he'll have to go back & change it later. Better to think these things out in advance.

~Begby is right though in that it'll probably be immeasurable until there's a huge load. A good bet would be to built a test case. Make a script that accesses your database 1000 times. You can use microtime() to time it. Run it once with mysql_fetch_assoc() and once with mysql_fetch_array(). If the times are very close, up your accesses to 2000, 3000 or whatever it takes until a clear winner is shown.

Yes, a table with 10 fields will be slower (although microscopically) than a table with 2 fields - since there's more data to chunk through. However, its much faster than having 5 tables with 2 fields & doing some query magic to get all the fields.

Posted: Tue Sep 18, 2007 4:31 pm
by Mightywayne
Super idea, Pickle! Thanks mang. Out of interest and thanks, I'll post my findings here.

Posted: Tue Sep 18, 2007 4:54 pm
by Mightywayne
Back! When I get back home, (like an hour) I'll do more testing, but wow.

3,000 queries and fetched, took .16 seconds average.

With assoc_, it was .14 seconds. :P

Thanks a lot. I think on a rainy day I'll go through my most popular scripts, and fix it up. With 30 users, I guess I needn't worry much. =P

Posted: Tue Sep 18, 2007 5:11 pm
by CoderGoblin
Something else to bear in mind with select is where possible don't use SELECT *, only return those columns you need. That does make a substantial difference for large tables, especially if you do not need some text columns.