This may be coming from the fact that Python caches 'low integer' objects. Therefor Python is just increasing a refcount and returning it's cached 0 object. For the larger values a python object is being allocated and then freed.I have run these tests about 10-15 times now, and am consistently getting the same results. Why is example B so slow? One would think it is doing exactly the same thing as Example A?
#Example A d = Numeric.zeros((10,10)) s = time.time() for i in xrange(10000): for y in xrange(len(d)): for x in xrange(len(d[y])): t = d[y,x] t + 1 print time.time() - s1.50099992752
#Example B
#map.sample returns a 10x10 array take from a surfarray.array2d()
d = map.sample(100,100) s = time.time()
for i in xrange(10000):
for y in xrange(len(d)):
for x in xrange(len(d[y])):
t = d[y,x]
t + 1
print time.time() - s
10.5379998684