title: @property speed overhead in Python
body: <p>I'm trying to understand the utility of the @property decorator in Python.  Specifically, I set up a class using properties like so:</p>
  
  <pre><code>class A(object):
      def __init__(self, x):
          self._x = x
  
      @property
      def x(self):
          return self._x
  
      @x.setter
      def x(self, new_x):
          self._x = new_x
  </code></pre>
  
  <p>And I also set up a class without properties providing the same functionality:</p>
  
  <pre><code>class B(object):
      def __init__(self, x):
          self._x = x
  </code></pre>
  
  <p>I create an instance of each:</p>
  
  <pre><code>a = A(10)
  b = B(10)
  </code></pre>
  
  <p>Running %timeit in iPython yields the following results</p>
  
  <pre><code>%timeit a.x
  %timeit b._x
  </code></pre>
  
  <p>1000000 loops, best of 3: 213 ns per loop</p>
  
  <p>10000000 loops, best of 3: 67.9 ns per loop</p>
  
  <pre><code>%timeit a.x = 15
  %timeit b._x = 15
  </code></pre>
  
  <p>1000000 loops, best of 3: 257 ns per loop</p>
  
  <p>10000000 loops, best of 3: 89.7 ns per loop</p>
  
  <p>Clearly, the @property and @setter decorators are inferior if you're going to be talking to the object with significant frequency.  My question is, simply, why use it?  I would be interested to hear any use-cases for these decorators that people may have.  Thanks.</p>