I see what you are doing and I am using something similar. It seems to me that you are not far enough away. I tend to encapsulate all data processing in one class, so I can cache the values ββthat are calculated until the list changes. eg:
public class StatProcessor{ private list<double> _data;
You will notice that with this method, only the first query for the average calculates the average. After that, until we add (or delete or modify at all, and those shown by arnt) something from the list, we can get the average value of basically nothing.
In addition, since the mean value is used in the standard deviation algorithm, calculating the standard deviation will first give us the mean for free, and calculating the mean first will give us a slight increase in performance in calculating the standard deviation, assuming we did not forget to check the flag.
Besides! places like the middle function, where you loop any value anyway, is a great time to cache things like min and max values. Of course, requests for this information should first check to see if they were cached, and which can lead to a relative slowdown compared to just detecting max using a list, since it does all the extra work of setting up all the relevant caches, not just your access .
Benjamin Oct 29 '12 at 17:08 2012-10-29 17:08
source share