[Pyrex] Pyrex method 10x slower than Python, any hints why?
David Chiang
dwchiang at yahoo.com
Wed May 31 22:40:43 UTC 2006
Hello all, when I compare this method
def estimate(self, r):
sum = 0.0
for i in xrange(r.e.arity()+1):
cost = lookup_words(self.ngram, None, [r.e.getchunk(i)], 1, 0, self.mapdigits, self.ceiling)
sum = sum + cost
return sum
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!
David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: estimate.c
Type: text/x-c
Size: 5252 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20060531/20f2937e/attachment.bin
More information about the Pyrex
mailing list