title: Is MATLAB faster than Python (little simple experiment)
body: <p>I have read this ( <a href="https://stackoverflow.com/questions/2133031/is-matlab-faster-than-python">Is MATLAB faster than Python?</a> ) and I find it has lots of ifs.</p>
  
  <p>I have tried this little experiment on an old computer that still runs on Windows XP.</p>
  
  <p>In MATLAB R2010b I have copied and pasted the following code in the Command Window:</p>
  
  <pre><code>tic
  x = 0.23;
  for i = 1:100000000
    x = 4 * x * (1 - x);
  end
  toc
  x
  </code></pre>
  
  <p>The result was:</p>
  
  <pre><code>Elapsed time is 0.603583 seconds.
  
  x =
  
      0.947347510922557
  </code></pre>
  
  <p>Then I saved a <strong><code>py</code></strong> file with the following script:</p>
  
  <pre><code>import time
  t = time.time()
  x = 0.23
  for i in range(100000000): x = 4 * x * (1 - x)
  elapsed = time.time() - t
  print(elapsed)
  print(x)
  </code></pre>
  
  <p>I pressed <kbd>F5</kbd> and the result was</p>
  
  <pre><code>49.78125
  0.9473475109225565
  </code></pre>
  
  <p>In MATLAB it took 0.60 seconds; in Python it took 49.78 seconds (an eternity!!).</p>
  
  <p><strong>So the question is</strong>: is there a simple way to make Python as fast as MATLAB?</p>
  
  <p><strong>Specifically</strong>: how do I change my <code>py</code> script so that it runs as fast as MATLAB?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have tried the same experiment in <strong><code>PyPy</code></strong> (copying and pasting the same code as above): it did it in 1.0470001697540283 seconds on the same machine as before.</p>
  
  <p>I repeated the experiments with 1e9 loops.</p>
  
  <p>MATLAB results:</p>
  
  <pre><code>Elapsed time is 5.599789 seconds.
  1.643573442831396e-004
  </code></pre>
  
  <p><code>PyPy</code> results:</p>
  
  <pre><code>8.609999895095825
  0.00016435734428313955
  </code></pre>
  
  <p>I have also tried with a normal <code>while</code> loop, with similar results:</p>
  
  <pre><code>t = time.time()
  x = 0.23
  i = 0
  while (i &lt; 1000000000):
      x = 4 * x * (1 - x)
      i += 1
  
  elapsed = time.time() - t
  elapsed
  x
  </code></pre>
  
  <p><strong>Results</strong>:</p>
  
  <pre><code>8.218999862670898
  0.00016435734428313955
  </code></pre>
  
  <p>I am going to try <strong><code>NumPy</code></strong> in a little while.</p>