Why Python IDLE is faster than Spyder or Jupyter notebook

• Python
Gold Member
I defined a simple prime function and then I append each number to an array up to 1 million and then later 2 million. In both cases, Python IDLE gives me the answer in 4 and 9 seconds respectively, but Spyder and Jupyter Notebook gave me in 12 and 24 seconds. I wonder why this happened. The time delay is doubled in each case and that's not something small.

Is Python IDLE the best in the case for performance? Or just, in this case, it gives me the best result but in other cases, I should use the other ones?

Also, I didn't run it on the PyCharm but what would be the speed of the same operation on that IDLE?

I am trying many IDLE's but I am not sure to use which one. What would be your ideas on idle on both performance and usability?

Python:
import time
start=time.time()
def prime(N):
if N==0 or N==1:
return False
y=int(N**(0.5))
for i in range(2,y+1):
if N%i==0:
return False
return True
A=[N for N in range(1000000) if prime(N)==True]
end=time.time()
Time=end-start
print("Time to solve",Time,"sec")

Runtime on Pyton IDLE: 4.639 sec

Runtime on Jupyter : 9.4383 sec

Runtime on Spyder : 8.633 sec

Related Programming and Computer Science News on Phys.org
StoneTemplePython
Gold Member
try doing your tests on larger, newer problems... a few seconds isn't such a big deal. Some of your tests may be getting an unfair headstart based on cache.

I mostly use Pycharm and Jupyter notebooks, occasionally Atom. Also, I thought time.clock() was preferred to time.time()? It's been a while since I looked into the mechanics of this.
- - - -
To be honest I wouldn't worry about any of this. Python has a massive community on the Internet and unless other people (e.g. on stack overflow) have repeatedly flagged this as an issue with various interpreters/platforms and running python, then it probably says more about your setup's idiosyncrasies than IDLE, Jupyter, etc.

I'd focus on my attention on learning programming techniques (e.g. I recall one of your challenge problems took well over an hour to solve, but many of us can solve it in under a second)... that should be more rewarding, and fun, right?

phinds
Gold Member
try doing your tests on larger, newer problems... a few seconds isn't such a big deal. Some of your tests may be getting an unfair headstart based on cache.
Thats possible I guess. But it sounds strange..I ll run some ther programs that I wrote and I ll test them.

I mostly use Pycharm and Jupyter notebooks, occasionally Atom. Also, I thought time.clock() was preferred to time.time()? It's been a while since I looked into the mechanics of this.
I saw that code on the net so I was using it .I ll look into it

To be honest I wouldn't worry about any of this. Python has a massive community on the Internet and unless other people (e.g. on stack overflow) have repeatedly flagged this as an issue with various interpreters/platforms and running python, then it probably says more about your setup's idiosyncrasies than IDLE, Jupyter, etc.
I wanted to use something else...I first downloaded Pycharm then I tried Spyder and Jupyter notebook. I thought they would be faster or at least Idk some advantage over the Python IDLE.I searched online and they say the best is Pycharm. Maybe I try another shot on that one

I'd focus on my attention on learning programming techniques (e.g. I recall one of your challenge problems took well over an hour to solve, but many of us can solve it in under a second)... that should be more rewarding, and fun, right?
Its I guess I am reading the book and I am studying online lectures by MIT. So eventually I ll get there somehow (I guess).

Also I recommend you sublime text 3. The name talks about it. Simple, beatifull, elegant and "free". I don't need more.

Gold Member
Also I recommend you sublime text 3. The name talks about it. Simple, beatifull, elegant and "free". I don't need more.
I looked at it it seems nice but I think its mostly for large number lines of vode I guess ? and I think it doesnt have a run ? I mean its just a text editor. Pycharm seems really nice in this case

From my experience, Jupyter notebook is insanely slow. It also tends to crash if the notebook is large. However, the GUI is absolutely beautiful, and you get to write Latex, HTML and markdown between your lines of code and create absolutely beautiful NOTEBOOKS. That's what it's designed to do. It's not designed for speed. Use it for data exploration, documentation and presentations, but never for speed. It's not designed for speed. If you're looking for speed, why are you using Python? It's about the aesthetics, man.

You can use Cython in Jupyter notebook, though. That may be worth experimenting with if speed is your goal. You would probably also want to write the code in Jupyter notebook but download the Jupyter notebook as a script and then run the script outside of Jupyter notebook.

Last edited: