[squeak-dev] Re: [Vm-dev] MadgwickAHRS plugin and support code

David T. Lewis lewis at mail.msen.com
Sun Sep 13 20:18:23 UTC 2015


On Sun, Sep 13, 2015 at 01:34:32PM +0200, Herbert K??nig wrote:
> Hi,
> 
> Am 13.09.2015 um 06:31 schrieb David T. Lewis:
> >Well it's basically the only convenient way to deal with float (as 
> >opposed to double) floating point values. In Squeak, a Float is a C 
> >double, and AFIK the only thing that directly represents single 
> >precision floats is FloatArray. You would be justified in being scared 
> >of them, especially if any of this sounds like it makes sense. But it 
> >does work and it might be more efficient than arrays of Float (C 
> >doubles). Or maybe not, I don't have any way to measure it. But I 
> >tried to set things up so that the FloatArray things can be reused to 
> >avoid allocations and type conversions, so maybe it will help. 
> 
> FloatArray offers a lot of speed up as long as the operations provided 
> by Float array are sufficient. Getting Squeak Floats into and out of 
> Float Array is expensive.
> This:
> Time millisecondsToRun:
>     [|array1 array2|
>     array1 := (1.0 to: 10000.0 by: 0.1) asArray.
>     array2 := (10000.0 to: 1.0 by: -0.1) asArray.
>     1000 timesRepeat: [|result|
>         result := array1  * array2]]
> 22 seconds
> is not much slower than using FloatArray
> Time millisecondsToRun:
>     [|array1 array2|
>     array1 := (1.0 to: 10000.0 by: 0.1) asArray.
>     array2 := (10000.0 to: 1.0 by: -0.1) asArray.
>     1000 timesRepeat: [|result|
>         result := (array1 asFloatArray * array2 asFloatArray)]]
> 19 seconds
> If you change the last line to use more operations supported by 
> FloatArray like:
>         result := (array1 asFloatArray * array2 asFloatArray + 7.0 * 
> 3.0) sum
> with FloatArrays you get the same speed, without the conversion to 
> FloatArray it takes three times as long.
> 
> If you need to use FloatArray>>at: and #at:put very often FloatArrays 
> may get slower than Arrays of Float.
> So benchmark and benchmark again.
> 
> And if your values get small, FloatArray may round them to zero which is 
> bad for division.
> 
> I used FloatArray a lot for  Audio processing and neural networks but 
> they need to be handled with care.
> I ended up using both depending on the algorithm.

Herbert,

Thanks, that is good to know. Indeed it might be faster to just use arrays
of Float, and it might be worth trying both ways to see which is better.

Dave

 


More information about the Vm-dev mailing list