I hacked up some code to test my hypothesis of algo complexity for set intersection in python:
s3, s4, s5, s6, t3, t4, t5, t6 are all defined and are rather large - their intersections also happen to be quite large.
import timeit
s3, t3 = set(), set()
s4, t4 = set(), set()
s5, t5 = set(), set()
s6, t6 = set(), set()
for x in xrange(int(1e3)):
s3.add(x)
t3.add(x*2 + x)
for x in xrange(int(1e4)):
s4.add(x)
t4.add(x*2 + x)
for x in xrange(int(1e5)):
s5.add(x)
t5.add(x*2 + x)
for x in xrange(int(1e6)):
s6.add(x)
t6.add(x*2 + x)
def _test():
for i in [3, 4, 5, 6]:
for j in [3, 4, 5, 6]:
if i >= j:
s, t = 's' + str(i), 't' + str(j)
print i, j
print timeit.timeit('{0}.intersection({1})'.format(s, t), setup="from __main__ import {0}, {1}".format(s, t))
eval('del s' + str(i))
But the following statement 'blows up'..
eval('del s' + str(i))
Any ideas?
I would also be interested in any ideas to make my hacky code less hacky.
Thanks