Created
February 1, 2016 21:55
-
-
Save 1st1/22c1aa0a46f246a31515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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