Created
May 10, 2012 17:33
-
-
Save tomekwojcik/2654619 to your computer and use it in GitHub Desktop.
Python @Property vs direct access
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
# -*- coding: utf-8 -*- | |
from timeit import timeit | |
setup = """\ | |
class Test(object): | |
def __init__(self, something): | |
self._something = something | |
@property | |
def something(self): | |
return self._something | |
test_obj = Test('dupa') | |
""" | |
without_accessor = timeit('a = test_obj._something', setup) | |
print 'Without accessor: ' + str(without_accessor) | |
with_accessor = timeit('a = test_obj.something', setup) | |
print 'With accessor: ' + str(with_accessor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment