title: Perfomance of serializing python list
body: <p>I have some trouble with perfomance in Python. In my wsgi application i'm serialize to json list of class. This is my code:</p>
  
  <pre><code>class Foo (object):
      def __init__(self, id,object_id, name_id,name,val,val2):
          self.id = id
          self.object_id = object_id 
          self.name_id = name_id 
          self.name = name
          self.val = val 
          self.add_val = val2
  
  
  def application(environ, start_response):
          status = '200 OK'
          q = list()
          response_headers = [('Content-type', "application/json")]
          start_response(status, response_headers)
          for i in range(1,50001):
              p = Foo(str(i),random.random(), 'col_3','col_4','col_5','col_6')
              q.append(p.__dict___)
          return json.dumps(q)
  </code></pre>
  
  <p>I got answer slow(about 18 sec). Then i rewrite code to this:</p>
  
  <pre><code>class Foo (object):
      def __init__(self, id,object_id, name_id,name,val,val2):
          self.id = id
          self.object_id = object_id 
          self.name_id = name_id 
          self.name = name
          self.val = val 
          self.add_val = val2
  
  
  def application(environ, start_response):
          status = '200 OK'
          q = list()
          response_headers = [('Content-type', "application/json")]
          start_response(status, response_headers)
          yield '['
          for i in range(1,50001):
              p = Foo(str(i),random.random(), 'col_3','col_4','col_5','col_6')
              yield json.dumps(p.__dict___)
          yield ']'
  </code></pre>
  
  <p>It's run more faster(about 4-6 sec). I can't understand why. Can you explain me why i have this results?
  PS i tried different json libs and got same results.</p>