Re: which is faster?
- Posted by CChris <christian.cuvier at agricu?ture.gouv.?r> Nov 08, 2007
- 629 views
I didn't quote original message, because the formatting was very messy and unreadable, I don't know why for sure. Instead of substracting m to every element, just do
m = mean(s) for i = 1 to l do -- sum of squared deviations sum += power(s[i], 2) end for sum -= m*m -- same result, but avoids the s-=m statement
I didn't check whether this was better:
atom si --... m = mean(s) for i = 1 to l do -- sum of squared deviations a = s[i] sum += a*a end for sum -= m*m
but I'd bet it's faster than calling power(). Also, computing the sum of elements of s inside the for loop will shave the call to mean() and speed things even more. CChris