On May 8, 2009, at 12:20 PM, Lisandro Dalcin wrote: > On Fri, May 8, 2009 at 7:08 AM, Brian Blais <[email protected]> wrote: >> On May 7, 2009, at 20:42 , Lisandro Dalcin wrote: >> >> Brian, in the Cython version, class Neuron, do this: instead of "def >> update(...)", please write "cpdef update(...)" and time your code >> again. If this make it faster (it should be near the C-struct >> version), please consider first removing your original "def update", >> and replace your "cdef _update()" by "cpdef update()". >> >> thanks, but this didn't change the time much at all (something >> like .5 ms >> out of 20ms). I was following the example in the cython docs >> Early Binding >> for Speed section, but now I see it got updated to cpdef! > > >> I'll keep hacking away at it. Perhaps I'll try a smaller example, >> to see >> the difference between lookups in classes and in structs, if that >> really is >> the issue. > > I'm almos sure that's the issue :-) > > Looking closer to your code, it seems the big offender is your > Connection class, as it attributes are bare "object" instances... > >> Is there a better way to find speed bottlenecks than the "comment >> out and >> re-compile" method? :) > > In general, any time to cdef'ine something as "object", you are going > to pay the cost of Python attribute lookup via a dict... Try do get > rid of these definitions in favor of explicit types... In short, write > Cython code as if you were writing C++, where you have to explicitly > type everything.
Well, the good thing is that one you only have to type the critical parts of the code, and can use the convienience of Python in not caring for the (usually) bulk of the code linewise that only takes 1% of the runtime. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
