Re: which is faster?

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu