title: Python if vs try-except
body: <p>I was wondering why the try-except is slower than the if in the program below. </p>
  
  <pre><code>def tryway():
      try:
          while True:
              alist.pop()
      except IndexError:
          pass
  
  def ifway():
      while True:
          if alist == []: 
              break
          else:
              alist.pop()
  if __name__=='__main__':
      from timeit import Timer
      alist = range(1000)
      print "Testing Try"
      tr = Timer("tryway()","from __main__ import tryway")
      print tr.timeit()
      print "Testing If"
      ir = Timer("ifway()","from __main__ import ifway")
      print ir.timeit()
  </code></pre>
  
  <p>The results I get are interesting. </p>
  
  <pre><code>Testing Try
  2.91111302376
  Testing If
  0.30621099472
  </code></pre>
  
  <p>Can anyone shed some light why the try is so much slower?</p>