title: Python while loop speed
body: <p>I would like it if someone could please explain to me why the following code has so much additional overhead. At 100k iterations, the speed is the same for either case (2.2 sec). When increasing to 1E6 iterations case "B" never finishes, while case "A" takes only 29 seconds.</p>
  
  <p><strong>Case "A"</strong></p>
  
  <pre><code>while n is not 1:
      foo
  </code></pre>
  
  <p><strong>Case "B"</strong></p>
  
  <pre><code>while n &gt; 1:
      foo
  </code></pre>
  
  <p>Complete code if of any help</p>
  
  <pre><code>def coll(n):
      count = 0
      # while n is not 1:
      while n &gt; 1:
          count += 1
          if not n % 2:
              n /= 2
          else:
              n = 3*n + 1
      return count
  
  for x in range(1,100000):
      count = coll(x)
  </code></pre>