question about xrange performance
Peter Otten
__peter__ at web.de
Fri Apr 17 15:11:00 EDT 2009
_wolf wrote:
> lately i realized a slow running portion of my application, and a
> quick profiling nourished the suspicion that, of all things, calls to
> `xrange().__contains__` (`x in b` where `b = xrange(L,H)`) is the
> culprit. to avoid any other influences, i wrote this test script with
> class `xxrange` being a poor man’s `xrange` replacement:
>
>
> ########################################################
> class xxrange( object ):
> def __init__( self, start, stop ):
> self.start = start
> self.stop = stop
> def __contains__( self, x ):
> return ( x == int( x ) ) and self.start <= x < self.stop
I haven't read
http://mail.python.org/pipermail/python-3000/2007-July/008971.html
completely, but from what I've read a patch might be accepted. Personally I
will continue to write
start <= x < stop
I don't remember an occasion where I needed the int(x) == x incantation or a
step (that you didn't implement).
Peter
More information about the Python-list
mailing list