Python For Loop Slowing With Time
Question: So I'm having a little trouble dealing with for loops in Python - as far as I
can tell, they're getting slower with time. I'm looping over a range inside of
a range, and as time passes, the loop noticeably slows. This is done inside of
a game engine, if it matters. Could anyone tell me what the issue is?

Here's a quick example.

    
    
    for x in range(xs): # xs, ys, and zs are all pre-determined size values
    
         for z in range(zs):
    
              for y in range(ys):
    
                  vp = [x * vs, y * vs, z * vs]
    
                  v = Cube(vp)
    

The initial speed of this process is fine, but with time the loop slows. I
know it's not anything else like the Rasterizer of the game engine because
when the loop is done, the rest of the engine runs at 60 FPS. So what could be
the problem?

EDIT: I'm using Python 3, so there is no xrange.

EDIT 2: For this example, vs is 1.0, and the predetermined size values of xs,
ys, and zs are all 20.


Answer: This is another case of "need more information". However, Python has a
standard way of constructing nested loops like this efficiently,
[`itertools.product`](http://docs.python.org/library/itertools.html#itertools.product):

    
    
    from itertools import product
    
    for x, y, z in product(xrange(xs), xrange(zs), xrange(ys)):
        vp = [x * vs, y * vs, z * vs]
        v = Cube(vp)
    

It doesn't require the construction of `range`s every time in the inner loop.
I also switched your use of `range` to `xrange`, as it's better for large
ranges, although this is really irrelevant with `product`.

@JohnZ's question is good -- if your "predetermined size values" are very
large, and especially if `vs` is also large, you could be constructing some
large values, and it could be taking a long time for `Cube` to process them.

I doubt the loop itself is slowing down, but the numbers are getting larger,
so your calculations might be.

