Reply to Re: Speed

Your name:

Reply:


Posted by Mark on 01/11/06 16:17

Peter Lauri wrote:

> Best group member,
>
>
>
> Assume that I save data about an object and it has 10.000 observations of
> the object stored in a MySQL database. I want calculate the average value
> of a column, is it faster done by using PHP on the result array or using
> the MySQL function to do that?
>
>
>
> /Peter

Hands down it will be the SQL database. To do an average, you must retrieve
all the data from disk anyway, that's your big hit, the summing all the
columns and dividing by the count is trivial compared to sending all that
data to a PHP box to do the average.

You would be better off all together figuring out how to not hit all those
records each time and keep a running average.

Something like:
$total_sum += $new_entry;
$count ++;
$avg = $total_sum/$count;

You will have to keep track of count and total_sum in some mutex locked type
of methodology, but any lock contention you get from it will almost
certainly out perform getting 10,000 records from a database.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация