Underneath the covers, IDLE mimics a terminal on top of a Tk widget, which I am sure is ultimately derived from Text .
Having long lines slows down this widget a bit. And adding to long lines takes longer than adding to short lines. If you really want to understand why this happens, you need to look at the Tcl code underlying the Tk Text widget, which Tkinter.Text just a thin wrapper around.
Meanwhile, the Tkinter loop that runs IDLE triggers some funky things, allowing it to accept input without blocking the loop. When he thinks that nothing else is happening, he can sometimes block for a short time until he sees the input or event Tk, and all these short blocks can add up; pressing Enter can just undo a few of them.
In fact, I'm not sure which of these two is more relevant. You will need to test it with a program that simply spams long lines compared to one that inserts new lines each, say, 10 numbers, and see how much of the performance improvement you get in this way.
From a quick test on my Mac, the original program noticeably slows down gradually, and also has two quantum transitions in the slowness of about 500 and 920. Thus, it makes sense that getting into them every 333 or so will speed up the process -You probably avoid both of these quantum downturns. If I change it to just remove the comma, the problem goes away.
Printing a new line for each number can, of course, cause another slowdown, since this makes the terminal long enough to scroll, increases the scroll buffer, etc. I did not see this value in IDLE, but I ran the same one on the Windows command line, and you will see problems with too many newlines as bad as problems with too few IDLEs. The best compromise should probably come from "square" data or data that is as close to 80 columns as possible without going over.
abarnert
source share