title: Why are python's for loops so non-linear for large inputs?
body: <p>I was benchmarking some python code I noticed something strange. I used the following function to measure how fast it took to iterate through an empty for loop:</p>
  
  <pre><code>def f(n):
      t1 = time.time()
      for i in range(n):
          pass
      print(time.time() - t1)
  </code></pre>
  
  <p><code>f(10**6)</code> prints about <code>0.035</code>, <code>f(10**7)</code> about <code>0.35</code>, <code>f(10**8)</code> about <code>3.5</code>, and <code>f(10**9)</code> about <code>35</code>. But <code>f(10**10)</code>? Well over <code>2000</code>. That's certainly unexpected. Why would it take over 60 times as long to iterate through 10 times as many elements? What's with python's for loops that causes this? Is this python-specific, or does this occur in a lot of languages?</p>