I noticed that when using print()
, these parameters significantly affected how quickly it got to the VSCode console, in ways that I do not understand.
I used time.time
to time some for loops counting to 100,000 with different parameters.
No end character specified, flush=false
: 13.01 s
No end character specified, flush=true
: 13.97 s
Why did this take longer than with the buffer? It seems like without the middleman it should go faster.
End=" "
, flush=false
: 0.47 s This seems like it would be the same as the first case, but printing a space instead of a newline character, does the newline character take that long to print? Does it have some sort of special functionality in the console?
End=" "
, flush=true
: 6.46 s
Once again, why is it longer without the buffer? And this one was 13x longer?!
Edit: I've only grown more confused: Printing with "end='\n'"
takes even longer than the first one! I thought all it was doing by default was appending a newline character?
source https://stackoverflow.com/questions/77856339/why-do-the-end-and-flush-parameters-affect-how-quickly-python-prints-to-the-cons
Comments
Post a Comment