[Scilab-users] any suggestion to make my Scilab code faster would be welcome:
Heinz Nabielek
heinznabielek at me.com
Wed May 16 19:44:18 CEST 2018
Yes- factor 10. Great many thanks for all the help.
Heinz
> On 16.05.2018, at 08:40, kjubo <kopac.jakub at gmail.com> wrote:
>
> Hello,
>
> d = zeros(n,1);
> for ii=1:n;
> // SqDist = (X-X(i))^2 + (Y-Y(i))^2 + (Z-Z(i))^2;
> SqDist = (X-X(ii)).*(X-X(ii)) + (Y-Y(ii)).*(Y-Y(ii)) +
> (Z-Z(ii)).*(Z-Z(ii));
> SqDist(ii)= [];
> d(ii) = sqrt(min(SqDist));
> end;
>
> some comments:
> * preallocate matrix
> * avoid unnecessary assign of variables (this slow down scilab more than
> expected)
> * as seen in previous meesages here, use X*X instead of X^2
>
> for me speed up factor is ~10
>
> Regards.
More information about the users
mailing list