title: Why are mutable strings slower than immutable strings?
body: <p>Why are mutable strings slower than immutable strings?</p>
  
  <p>EDIT:</p>
  
  <pre><code>&gt;&gt;&gt; import UserString
  ... def test():
  ...     s = UserString.MutableString('Python')
  ...     for i in range(3):
  ...         s[0] = 'a'
  ... 
  ... if __name__=='__main__':
  ...     from timeit import Timer
  ...     t = Timer("test()", "from __main__ import test")
  ...     print t.timeit()
  13.5236170292
  
  
  
  &gt;&gt;&gt; import UserString
  ... def test():
  ...     s = UserString.MutableString('Python')
  ...     s = 'abcd'
  ...     for i in range(3):
  ...         s = 'a' + s[1:]
  ... 
  ... if __name__=='__main__':
  ...     from timeit import Timer
  ...     t = Timer("test()", "from __main__ import test")
  ...     print t.timeit()
  6.24725079536
  
  
  &gt;&gt;&gt; import UserString
  ... def test():
  ...     s = UserString.MutableString('Python')
  ...     for i in range(3):
  ...         s = 'a' + s[1:]
  ... 
  ... if __name__=='__main__':
  ...     from timeit import Timer
  ...     t = Timer("test()", "from __main__ import test")
  ...     print t.timeit()
  38.6385951042
  </code></pre>
  
  <p>i think it is obvious why i put s = UserString.MutableString('Python') on second test.</p>