On Jul 26, 2013 9:58 AM, "Sturla Molden" <stu...@molden.no> wrote:
>
> On 26.07.2013 01:24, Zak wrote:
>
>> When I statically declare a variable as a Python type, I am wondering if
>> there is any performance benefit in any case. I have run some tests and
>> seen no performance impact at all.
>
>
> Sometimes!
>
> * Declaring a Python type (or just "cdef object") avoids the dictionary lookups when you access the variable. It can also avoid unneeded reference counting when accessing a variable. This can be a huge performance gain if the variable is accessed often.
>
> * cdef variables are not accessible from Python. Thus you can protect them from modification from Python.
These two points are for global variables, and in that case there can be quite a boost.
> * Declaring a Python type can make Cython optimize certain calls, such as indexing and appending.
>
>
> Sturla
>
>
>
>
>