Out of curiosity, would most of the time be spent on the line "return self.obj[self.i]"? It seems like a __getitem__ call would be much slower than anything else in the class.
-Aaron On Sat, Dec 6, 2008 at 11:39 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote: > Hi, > > Jelle Feringa wrote: >> cdef class FastLoopObj1d: >> >> cdef int N, i >> cdef object obj >> >> def __init__(self, n, obj ): >> self.N = n-1 >> self.i = 0 >> self.obj = obj >> >> def __iter__(self): >> return self >> >> # no cpdef allowed? >> def __next__( self ): >> if self.i < self.N: >> self.i+=1 >> return self.obj[self.i] >> else: >> raise StopIteration >> >> I noticed that the cython iterator is about twice as fast compared to >> the python version, when indexing an iterable object. >> A respectable speedup, given how trivial the implementation is. Would >> you consider the implementation optimal? Is this the fastest way of >> indexing an iterable object? > > This looks a bit like a stripped down version of itertools.islice() to me. > Have you tried that instead? > > Stefan > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
