So here is my simple code:
#Set implementations benchmark
seta = set([random.randint(0,100000) for n in xrange(10000)])
setb =set([random.randint(0,100000) for n in xrange(10000)])
t0 = time.clock()
for i in xrange(1000):
seta & setb
seta | setb
seta ^ setb
print "Time: %s seconds"%(time.clock()-t0)
and here are the timings:
$ python set_bench.py
Time: 9.45 seconds
$ ipy set_bench.py
Time: 141.460593000 seconds
CPython is simply 15 times faster than Iron Python!
I always like to have external tool for comparison. So I converted my little Python script to C++ with ShedSkin, compiled and ran it:
Time: 30.66 seconds
CPython was still more than 3 times faster than the C++ generated by ShedSkin (0.0.21)!!
For the reference: I used IronPython 1.0.2467 on .NET 2.0.50727.42 on an Ubuntu machine. It would be nice if someone could re-run this on a Windows box.
If anyone knows of a faster solution for determining the intersection between two sets in Python (perhaps using dictionaries?), I would be very interested to know.