(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?
[solved] Two things I've always wondered.
Moderator: General Moderators
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
[solved] Two things I've always wondered.
Last edited by Mightywayne on Tue Sep 18, 2007 8:23 pm, edited 1 time in total.
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.
~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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
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.
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
3,000 queries and fetched, took .16 seconds average.
With assoc_, it was .14 seconds.
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
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany