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

Eliot Miranda eliot.miranda at gmail.com
Mon Sep 14 21:07:14 UTC 2015


Hi Herbert,

On Sun, Sep 13, 2015 at 4:34 AM, Herbert König <herbertkoenig at gmx.net>
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.
>

That's right.  Using FloatArray implies an object allocation on every at:,
to construct the (boxed) Float result.  64-bit Spur will change this
equation because most of the time the floats fetched will be immediate,
instances of SmallFloat64.  And indeed they may make it attractive to have
a 64-bit float array type.


> 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.
>
> Cheers,
>
> Herbert
>
>
>
>


-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150914/09bd1bbd/attachment.htm


More information about the Squeak-dev mailing list