# Mintoris Forum

### Author Topic: Speed of array processing  (Read 3319 times)

#### lancegary

• Full Member
• Posts: 24
##### Speed of array processing
« on: Jan 24, 2011, 09:49 AM »
I posted some array routines for calculating the sum, the average and the variance of the numbers in an array.

The routine for calculating the variance of the numbers in an array used standard "For‥Next" loops. It is possible to re-write that routine to just use Array operations. For example to calculate the deviations from the mean one could write:

C() = testArray() - Mean

And to calculate the squared deviations one could write:

D() = C() * C()

I wondered about the relative speed of the array operations compared with For ‥ Next loops and also about memory usage. If one has fairly large data sets array operations could perhaps consume a great deal of memory?

Lance

#### Chuck

• Global Moderator
• Hero Member
• Posts: 1899
##### Re: Speed of array processing
« Reply #1 on: Jan 25, 2011, 03:27 AM »
I posted some array routines for calculating the sum, the average and the variance of the numbers in an array.

The routine for calculating the variance of the numbers in an array used standard "For‥Next" loops. It is possible to re-write that routine to just use Array operations. For example to calculate the deviations from the mean one could write:

C() = testArray() - Mean

And to calculate the squared deviations one could write:

D() = C() * C()

I wondered about the relative speed of the array operations compared with For ‥ Next loops and also about memory usage. If one has fairly large data sets array operations could perhaps consume a great deal of memory?

Lance

Those array operations look like they will work.  It is always better to use array operations than for…next loops.  Array operations do take up more memory, but Basic will tell you when you run out.  All the memory gets recycled.

If there are generalized array functions that you would like to see as built in functions just let me know.  Anything you think other people might use.  I think all these types of functions should start with Mat as in:

s() = MatSum(a())

These types of functions will always execute much faster than using Basic and for…next loops.

-Chuck

#### lancegary

• Full Member
• Posts: 24
##### Re: Speed of array processing
« Reply #2 on: Jan 26, 2011, 11:24 AM »

Those array operations look like they will work.  It is always better to use array operations than for…next loops.  Array operations do take up more memory, but Basic will tell you when you run out.  All the memory gets recycled.

If there are generalized array functions that you would like to see as built in functions just let me know.  Anything you think other people might use.

Thanks for the information - much appreciated

Quote

I think all these types of functions should start with Mat as in:

s() = MatSum(a())

These types of functions will always execute much faster than using Basic and for…next loops.

-Chuck

MatSum() seems fine, but I'm a little hesitant to call a function MatMult() when it is not doing the same thing as a matrix multiplication. (In linear algebra you multiple the rows of one matrix with the columns of the other matrix when two matrices are multiplied.) So my worry would be not to confuse matrix operations of the sort done in linear algebra with (the very useful but different) array operations found in Mintoris BASIC. Perhaps this is a trivial issue?