I'm missing something here with range vs. xrange

Joe Goldthwaite joe at goldthwaites.com
Thu Dec 6 17:06:53 EST 2007


I've been playing with Python a bit. Doing little performance benchmarks and
working with Psyco.  It's been fun and I've been learning a lot.  For
example, in a previous post, I was looking for a way to dynamically add new
runtime function to a class.  Martin told me to use a class instance
variable instead.  It turns out that's faster than hard coding a list of
functions.  Thanks Martin.

I read that the range function builds a list and that xrange returns an
iterator and is therefore more efficient.  In my testing, they both come out
to almost exactly the same performance wise.  Did something get changed in
Python 2.4 to make them identical?  I searched the web but couldn't find
anything that would account for the similarities.





More information about the Python-list mailing list