Created
October 4, 2016 22:31
-
-
Save ruoyu0088/d00e3a8970ce457175e49b17893157c2 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
class A: | |
def __init__(self): | |
self.x = 1 | |
self.y = 2 | |
def get_x(self): | |
return self.x | |
def get_y(self): | |
return self.y | |
a = A() | |
%timeit a.x | |
%timeit a.get_x() | |
%timeit getattr(a, "x", None) | |
""" | |
output: | |
10000000 loops, best of 3: 150 ns per loop | |
1000000 loops, best of 3: 598 ns per loop | |
1000000 loops, best of 3: 388 ns per loop | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment