Here's the lookup-speed script. num = 1000000 code = """ x = None r = range(%d) def builtin_lookup(): for i in r: len; len; len; len len; len; len; len len; len; len; len len; len; len; len def global_lookup(): for i in r: x; x; x; x x; x; x; x x; x; x; x x; x; x; x def local_lookup(): x = None for i in r: x; x; x; x x; x; x; x x; x; x; x x; x; x; x def overhead(): for i in r: pass """ % num class D(dict): pass class E(dict): __getitem__ = lambda s, k: dict.__getitem__(s, k) print "Timing %d name lookups" % (num*4) print "%8s %8s %8s %8s %8s" % ("type", "builtin", "global", "local", "overhead") import time for dc in dict, D, E: d = dc() exec code in d print "%8s" % dc.__name__, for f in ("builtin_lookup()", "global_lookup()", "local_lookup()", "overhead()"): t0 = time.time() exec f in d t1 = time.time() print "%8.5f" % (t1-t0), print
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4