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

Reply via email to