2

I noticed several times that a simple python script (with some straightforward algebraic computation in a loop) runs considerably faster (up to a factor 6) when launched on a shell command line as compared to a run via IDLE's shell. There is nothing fancy going on in the script. I only print a loop variable to visually follow progress in the loop.

Surely just this print statement cannot be the reason for the speed loss in IDLE, or can it ?

Can someone explain me why this is ?

  • Hi, do you mean the interactive interpreter in IDLE? Or running it from IDLE once saved? – Joe Doherty Feb 26 '13 at 09:51
  • I mean running it from IDLE once saved. The loop really is just a big numerical computation albeit containing some class method calls. – Mathias Vanwolleghem Feb 26 '13 at 10:27
  • Sounds strange. I don't have idle at the moment to test just have headless Ubuntu box. You could try this code in both to see what the outcome would give `import timeit \\ print timeit.Timer('for i in range(0, 10000): print i').timeit(number=100)` that would limit it down to just the`print` the problem may be that printing the text in the GUI is slower than having the OS do it – Joe Doherty Feb 26 '13 at 10:44
  • That is amazing ! First of all I am rather a newbie to more advanced python tools such as the timeit module. So thanks for introducing me to this. But more importantly when running this (I reduced the number of tests to 10 to get a result more quickly) the result via IDLE was 220 sec for printing 10 times the numbers from 1 till 10000, .... and a mere 1.2 sec (!!!) for the same script launched via the command line. Is this trustworthy or is there a problem with my IDLE install ? – Mathias Vanwolleghem Feb 26 '13 at 11:32
  • @danodonovan below has posted the reason why. You are likley to see this issue when using a GUI rather than using the console. There is all the over heads with the GUI which would cause some problems. :) – Joe Doherty Feb 26 '13 at 13:18

1 Answers1

1

The Tkinter text widget is slow, and IDLE uses this to print text to screen.

See this question.

Community
  • 1
  • 1
danodonovan
  • 19,636
  • 10
  • 70
  • 78
  • Well, shouldnt this be a major worry then for Tkinter developers? I mean how more badly can your tool be developed if just printing an integer slows down the code execution by two orders of magnitude ? – Mathias Vanwolleghem Feb 26 '13 at 13:33
  • @MathiasVanwolleghem no, because if you're developping, you shouldn't really about performance. If you do, run the same code in console. – logicOnAbstractions Dec 08 '21 at 15:42