# # Perdormance Benchmark # import os import timeit import subprocess from zope.interface import Interface, Attribute print "Performance bench" print "-----------------" s1 = """\ class I1(Interface): a1 = Attribute('one') a2 = Attribute('two') a3 = Attribute('thee') a4 = Attribute('four') a5 = Attribute('five') def f1(arg): pass def f2(arg): pass def f3(arg): pass def f4(arg): pass def f5(arg): pass """ t = timeit.Timer(stmt=s1, setup="from zope.interface import Interface, Attribute") print "one interface, 5 methods, 5 functions: %.2f usec/pass" % (1000000 * t.timeit(number=10000)/10000) s1 = """\ class I1(Interface): pass class I2(I1): pass class I3(I2): pass class I4(I3): pass class I5(I4): pass """ t = timeit.Timer(stmt=s1, setup="from zope.interface import Interface, Attribute") print "five inheriting interfaces: %.2f usec/pass" % (1000000 * t.timeit(number=10000)/10000) s1 = """\ class I1(Interface): pass """ t = timeit.Timer(stmt=s1, setup="from zope.interface import Interface, Attribute") print "one interface: %.2f usec/pass" % (1000000 * t.timeit(number=10000)/10000) setup = """\ from zope.interface import Interface, Attribute class I1(Interface): pass """ s1 = """\ I1.queryTaggedValue('bob') """ t = timeit.Timer(stmt=s1, setup=setup) print "query uninitialized tagged value: %.2f usec/pass" % (1000000 * t.timeit(number=50000)/50000) setup = """\ from zope.interface import Interface, Attribute class I1(Interface): pass I1.setTaggedValue('bob', 'bobby') """ s1 = """\ I1.queryTaggedValue('bob') """ t = timeit.Timer(stmt=s1, setup=setup) print "query initialized tagged value: %.2f usec/pass" % (1000000 * t.timeit(number=50000)/50000) print print "Memory bench" print "------------" pid = os.getpid() import gc gc.collect() gc.collect() gc.collect() print 'Memory before (kb):' subprocess.call(['/bin/ps', '-o', 'rss,vsize', str(pid)]) before_objects = len(gc.get_objects()) log = [] for i in range(3000): class I1(Interface): a1 = Attribute('one') a2 = Attribute('two') a3 = Attribute('thee') a4 = Attribute('four') a5 = Attribute('five') def f1(arg): pass def f2(arg): pass def f3(arg): pass def f4(arg): pass def f5(arg): pass log.append(I1) gc.collect() gc.collect() gc.collect() print "objects created: %s" % (len(gc.get_objects()) - before_objects) print 'Memory after (kb):' subprocess.call(['/bin/ps', '-o', 'rss,vsize', str(pid)])