Skip to content

Instantly share code, notes, and snippets.

@1st1
Created February 1, 2016 21:55
Show Gist options
  • Save 1st1/22c1aa0a46f246a31515 to your computer and use it in GitHub Desktop.
Save 1st1/22c1aa0a46f246a31515 to your computer and use it in GitHub Desktop.
import time
class F:
def __getattr__(self, name):
if name == 'spam':
return 42
def foo(f):
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
f.spam
def test():
f = F()
# warmup
for _ in range(10000):
foo(f)
# bench
st = time.monotonic()
for _ in range(10**6):
foo(f)
print(time.monotonic() - st)
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment