# ******* # WARNING # ******* # # to translate this target you need to apply get_fast.patch import sys import time keys = ['co_argcount', 'co_stacksize', 'co_code', 'magic'] k1, k2, k3, k4 = keys h1, h2, h3, h4 = map(hash, keys) # _____ Define and setup target ___ def target(*args): return entry_point, None def entry_point(argv): if len(argv) == 2: N = int(argv[1]) else: N = 50000000 print N, 'iterations' d = {k1: 1, k2: 2, k3: 3, k4: 4} total1 = 0 st1 = time.clock() for i in range(N): total1 += d.get(k1, -1) + d.get(k2, -1) + d.get(k3, -1) + d.get(k4, -1) et1 = time.clock() total2 = 0 st2 = time.clock() for i in range(N): total2 += d.get_fast(k1,-1,h1) + d.get_fast(k2,-1,h2) + d.get_fast(k3,-1,h3) + d.get_fast(k4,-1,h4) et2 = time.clock() t1 = et1-st1 t2 = et2-st2 print 'get: ', t1, 'seconds' print 'get_fast: ', t2, 'seconds' print print 'get_fast: %f times faster' % (t1/t2) assert total1 == total2 return 0 if __name__ == '__main__': print "Cannot run on CPython" #entry_point(sys.argv)