[Microbit-Python] Slowness as integers move beyond 256

M.-A. Lemburg mal at egenix.com
Wed Jan 6 04:45:34 EST 2016


Hi Damien,

On 06.01.2016 01:12, Damien George wrote:
> Hi Marc-Andre,
> 
> Wow, that's some really interesting behaviour!  I can confirm both the
> slow down and MemoryError.
> 
> The slow down at offset 252 is not due to integer arithmetic, but
> rather the underlying floating point implementation of the sine
> function.  sin(201) is fast, sin(202) is slow (test it by making a
> function that computes the sine 200 times and see how fast it runs
> with different args).  This is most likely due to the extra arithmetic
> that's needed to reduce large arguments (202 is large here) down to a
> range within -pi to pi (or something like that).

Thanks for the insight. I was just speculating on the reason
and the break near 256 together with my use of an integer
for the offset made it look like related to integers :-)

I'll see whether I can use a different strategy to
work around the sine range limit.

> As for the memory error, I'll need to look into that.  The GC is not
> properly collecting the memory used to create the "offset" strings
> (everything else is inplace).

Ah, so the debug output is triggering this. That's interesting.

Cheers,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jan 06 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/


> On Tue, Jan 5, 2016 at 10:55 PM, M.-A. Lemburg <mal at egenix.com> wrote:
>> [Sorry, hit send to early]
>>
>> I've been playing with MicroPython a bit and noticed a strange
>> behavior: integer math gets rather slow when reaching numbers
>> above 256.
>>
>> Run the attached script as example. It produces a wave on the
>> LED display and runs quite nicely until the offset reaches 251.
>> Performance then drops to about half the speed.
>>
>> Is this known behavior and expected ?
>>
>> I also noticed that the script stops when the offset reaches 500
>> with a MemoryError, even though the data structure for the LEDs
>> is modified in place, so perhaps it's not the math that's slowing
>> things down, but instead some memory leak.
>>
>> --
>> Marc-Andre Lemburg
>> eGenix.com
>>
>> Professional Python Services directly from the Experts (#1, Jan 05 2016)
>>>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>>>> Python Database Interfaces ...           http://products.egenix.com/
>>>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
>> ________________________________________________________________________
>>
>> ::: We implement business ideas - efficiently in both time and costs :::
>>
>>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>>            Registered at Amtsgericht Duesseldorf: HRB 46611
>>                http://www.egenix.com/company/contact/
>>                       http://www.malemburg.com/
>>
>>
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
> 



More information about the Microbit mailing list