Some simple performace tests (long)

Justin Azoff justin.azoff at gmail.com
Sat Aug 6 19:57:39 EDT 2005


How much ram does your machine have?
the main point is "except when a very large range is used on a
memory-starved machine"


run
x = range(10 ** 6)
and look at the memory usage of python..

what happens when you run this program:

import time

def t(func, num):
    s = time.time()
    for x in func(num):
        pass
    return time.time() - s

def run(func, num):
    times = []
    for x in range(5):
        times.append(t(func,num))
    return min(times), max(times), sum(times)/5

def main():
    x = 10 ** 6
    while 1:
        print "trying", x
        for s, f in ('xr', xrange), (' r', range):
            print s + " %.3f %.3f %.3f" % run(f, x)
        x *= 1.5
        x = int(x)


if __name__ == "__main__":
    main()


I get (columns are mix/max/average):

trying 1000000
xr 0.110 0.115 0.111
 r 0.101 0.186 0.119
trying 1500000
xr 0.082 0.087 0.083
 r 0.152 0.158 0.154
trying 2250000
xr 0.124 0.138 0.128
 r 0.228 0.235 0.230
trying 3375000
xr 0.184 0.189 0.186
 r 0.344 0.352 0.346
trying 5062500
xr 0.276 0.284 0.279
 r 0.515 0.528 0.519
trying 7593750
xr 0.415 0.421 0.416
 r 0.774 0.795 0.779
trying 11390625
xr 0.623 0.634 0.626
 r 1.163 1.246 1.180
trying 17085937
xr 0.934 0.941 0.937
Killed

The "Killed" is from the linux OOM killing the python process.. notice
that the xrange for that number worked fine.




More information about the Python-list mailing list