Skip to content

Instantly share code, notes, and snippets.

@tomekwojcik
Created May 10, 2012 17:33
Show Gist options
  • Save tomekwojcik/2654619 to your computer and use it in GitHub Desktop.
Save tomekwojcik/2654619 to your computer and use it in GitHub Desktop.
Python @Property vs direct access
# -*- 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