logo       

Re: Pyrex method 10x slower than Python, any hints why?: msg#00003

python.pyrex

Subject: Re: Pyrex method 10x slower than Python, any hints why?

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.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise