title: Python: Performance between readline and readlines
body: <p>I know the generally difference between readlines and readline of file object. But Im more curious how their performance differ from each other, thus I made a test here.</p>
  <pre><code>import timeit
  
  with open('test.txt', 'w') as f:
      f.writelines('\n'.join(&quot;Just a test case\tJust a test case2\tJust a test case3&quot; for i in range(1000000)))
  
  def a1():
      with open('test.txt', 'r') as f:
          for text in f.readlines():
              pass
  def a2():
      with open('test.txt', 'r') as f:
          text = f.readline()
          while text:
              text = f.readline()
  
  
  print(timeit.timeit(a1, number =100))
  print(timeit.timeit(a2, number =100))
  </code></pre>
  <pre><code>$python readline_vs_readlines.py
  38.410646996984724
  35.876863296027295
  </code></pre>
  <p>But Why is that? I think io is more time consuming so if you read more times instead of read it into the memory in once, it takes more time. So from what im seeing here, why we use <code>readlines</code> anyway? It costs us enormous amount of memory if file is large with no gain on speed?</p>