title: When is StringIO used, as opposed to joining a list of strings?
body: <p>Using StringIO as string buffer is slower than using list as buffer. </p>
  
  <p>When is StringIO used?</p>
  
  <pre><code>from io import StringIO
  
  
  def meth1(string):
      a = []
      for i in range(100):
          a.append(string)
      return ''.join(a)
  
  def meth2(string):
      a = StringIO()
      for i in range(100):
          a.write(string)
      return a.getvalue()
  
  
  if __name__ == '__main__':
      from timeit import Timer
      string = "This is test string"
      print(Timer("meth1(string)", "from __main__ import meth1, string").timeit())
      print(Timer("meth2(string)", "from __main__ import meth2, string").timeit())
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>16.7872819901
  18.7160351276
  </code></pre>