title: Why Python is so slow for a simple for loop?
body: <p>We are making some <code>kNN</code> and <code>SVD</code> implementations in Python.  Others picked Java. Our execution times are very different. I used cProfile to see where I make mistakes but everything is quite <a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips" rel="noreferrer">fine</a> actually. Yes, I use <code>numpy</code> also. But I would like to ask simple question.</p>
  
  <pre><code>total = 0.0
  for i in range(9999): # xrange is slower according 
      for j in range(1, 9999):            #to my test but more memory-friendly.
          total += (i / j)
  print total
  </code></pre>
  
  <p>This snippet takes 31.40s on my computer.</p>
  
  <p>Java version of this code takes 1 second or less on the same computer. Type checking is a main problem for this code, I suppose. But I should make lots of operation like this for my project and I think 9999*9999 is not so big number.</p>
  
  <p>I think I am making mistakes because I know Python is used by lots of scientific projects. But why is this code so slow and how can I handle problems bigger than this?</p>
  
  <p>Should I use a JIT compiler such as <code>Psyco</code>?</p>
  
  <h2>EDIT</h2>
  
  <p>I also say that this loop problem is only an example. The code is not as simple as like this and It may be tough to put into practice your improvements/code samples.</p>
  
  <p>Another question is that can I implement lots of data mining &amp; machine learning algorithms with <code>numpy</code> and <code>scipy</code> if I use it correctly? </p>