[Python-Dev] Algoritmic Complexity Attack on Python (original) (raw)

Jeremy Hylton jeremy@zope.com
29 May 2003 17:01:19 -0400


Scott,

I just too a minute too look at this. I downloaded the python-attack file from your Web site. I loading all the strings and then inserted them into a dictionary. I also generated a list of 10,000 random strings and inserted them into a dictionary.

The script is below.

The results show that inserting the python-attack strings is about 4 times slower than inserting random strings.

slothrop:/src/python/dist/src/build> ./python ~/attack.py ~/python-attack time 0.0898009538651 size 10000 slothrop:/src/python/dist/src/build> ./python ~/attack.py ~/simple
time 0.0229719877243 size 10000

Jeremy

import time

def main(path): L = [l.strip() for l in open(path)]

d = {}
t0 = time.time()
for k in L:
    d[k] = 1
t1 = time.time()
print "time", t1 - t0
print "size", len(d)

if name == "main": import sys main(sys.argv[1])