On 3 Sep, 15:39, [EMAIL PROTECTED] wrote: > Thanks for all the answers to my question. I think what I need to take > away from this is that xrange is an object
Indeed, but using xrange can be faster than converting your "for" loops to "while" loops plus a counter; I converted your code to use the latter arrangement and it was noticeably slower. Perhaps the repeated invocation of each xrange object's next method is less expensive than repeatedly obtaining new incremented int objects and testing them against other int objects. > - I thought it was just some loop construct, and that maths is slow in > python - so avoid pathological looping. You'd be wise to avoid doing unnecessary work deep within nested loops in any programming language. Sadly, it's not possible for the compiler to work out that some calculations can be lifted out of the innermost loops in Python, since the various guarantees that make such operations possible in other languages are not offered by Python. > I remember the first time I tried Objective-C on OS X I used the > NSNumber class for arithmetic - the results that time were pretty > awful too! Obviously, it'd be a fairer test if you used comparable numeric types in both implementations, but a more capable numeric type would be overkill for the C implementation of this program, and a less capable numeric type doesn't exist for Python unless you're willing to use a dialect such as Pyrex (as others have shown). Paul -- http://mail.python.org/mailman/listinfo/python-list