[Pyrex] Pyrex method 10x slower than Python, any hints why?

Andrew Bennetts andrew-pyrex at puzzling.org
Fri Jun 2 02:21:46 UTC 2006


On Wed, May 31, 2006 at 03:40:43PM -0700, David Chiang wrote:
[...]
>    against a Pyrex equivalent
>    
>        def estimate(self, rule.Rule r):
>            cdef float sum, cost
>            cdef int i
>            sum = 0.0
>            for i from 0 <= i <= r.e.arity():
>               cost = lookup_words(self.ngram, None, [r.e.getchunk(i)], 1, 0, self.mapdigits, self.ceiling) 
>                sum = sum + cost
>                                                                                   
>            return sum
>  
>  where the containing class is a user class and self.ngram, r, and r.e are
>  instances of extension types, the Python version runs, it would seem, 10
>  times faster. I've looked a bit at the generated C code (attached) and didn't
>  see anything obviously wrong; does anyone have any hints about what may be
>  going on? I realize this is kind of a vague question but any pointers for
>  further testing would be appreciated. Thanks in advance!

Perhaps the difference is that Python's eval loop special cases arithmetic
operations on numeric types quite heavily, but the same loop in Pyrex has to
resort to function calls?

-Andrew.




More information about the Pyrex mailing list