On Tue, May 26, 2009 at 6:03 PM, Dag Sverre Seljebotn <[email protected]> wrote: > Lisandro Dalcin wrote: >> Wow... I'm very sorry. I got it totally wrong ... >> >> If the change you are proposing about simplifying the type system only >> affect that, I'm actually +1 on your proposal. The canonical Python >> way is a mess in the context of Cython. >> >> I would just ask for the following: >> >> 1) When going from C to Python, for Python 2.X, try to avoid returning >> a PyLong (basically dispach proper calls using >> sizeof(type)<=sizeof(long) ) >> >> 2) Use __Pyx_T_FLOATING, just to avoid confussion. >> >> >> Of course, other way would be to just use the transform I proposed >> previously. I do not expect it to impact performance. > > To follow up here: Since Robert was concerned and I'm too lazy to > benchmark, I redid it. (This also fixes the recently reported bug of > course.) >
But you are really, really lazy ;-) ... Try this: $ python -m timeit -n 10000000 -s 'import sys; f=sys.stdout' 'f.softspace' 10000000 loops, best of 3: 0.218 usec per loop $ python -m timeit -n 10000000 -s 'import sys; f=sys.stdout' 'f.closed' 10000000 loops, best of 3: 0.194 usec per loop So very little difference... Dict lookups likely dominate: $ python -m timeit -n 10000000 -s 'd=file.__dict__' 'd["closed"]' 10000000 loops, best of 3: 0.177 usec per loop $ python -m timeit -n 10000000 -s 'd=file.__dict__' 'd["softspace"]' 10000000 loops, best of 3: 0.168 usec per loop Even if we ignore the overhead of dict lookups, a PyMemberDef-based attribute (the outcome of 'cdef public something') should have almost identical overhead to a PyGetSetDef-based attribute (the outcome of 'cdef property'). Moreover, the former (PyMemberDef) requires a dispatching switch, then being perhaps a bit less efficient? The numbers above seems to support me, though I should do a better test (softspace is a 'int' and 'closed' a 'bool'). > > http://hg.cython.org/cython/rev/11e826f95cde > Looks good. Though perhaps in the future we could review all this and get rid at all of PyMemberDef-based attributes... IMHO, that is just sugar for human C extension writers. -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
