Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython notebook 11 times slower than python: why?

I am running a script in ipython notebook (with Chrome) and noticed that it's 11 times slower than it is if I run the very same script in Python, using spyder as my IDE. The script is quite simple: it's just a set of loops and calculations on a pandas dataframe. No output is printed to the screen nor written to external files. I expect the code to be slowish because it's not vectorised, I appreciate Ipython may involve some overhead, but 11 times... ! Can you think of any reasons why? Any suggestions?

Thanks!

like image 750
Pythonista anonymous Avatar asked May 21 '15 17:05

Pythonista anonymous


1 Answers

I tested this on my machine, and found that ipython was actually faster.

$ cat ex.py 
import time
import numpy as np
now = time.time() #(seconds)
a = []
for j in range(2):
  for s in range(10):
    a.append(np.random.random())
then = now
print(time.time() - then)

$ python ex.py 
0.142902851105

In [1]: %run ex.py
0.06136202812194824

I bet it's the Chrome part of your ipython setup which is causing the slowdown.

like image 187
kilojoules Avatar answered Sep 17 '22 14:09

kilojoules