r/java • u/stymiee • Feb 24 '14
Why printing "B" is dramatically slower than printing "#"
http://stackoverflow.com/q/21947452/25025912
Feb 24 '14
This isn't really java. This has to do with incredibly low level (probably native) implementation that is platform specific.
7
u/KidUncertainty Feb 24 '14
Not sure why you are getting downvoted on that, since the Stackoverflow accepted answer is exactly that: the user was being hit by their shell terminal trying to word-wrap instead of character-wrap.
4
u/Neebat Feb 24 '14
Doesn't the Eclipse console do word-wrapping? While not absolutely java-specific, that would be quite relevant to Java.
3
u/KidUncertainty Feb 24 '14
An excellent question; I am not sure that it wordwraps. It does have a fixed-width and non-fixed width option. I tried the code from the Stackoverflow post.
In fixed-width mode set to 80 columns the console breaks (Eclipse throws exceptions). Without fixed-width mode, both variants of the application work fine and have equal execution speeds (on the order of 1.1 seconds on my environment).
However judging by the Eclipse UI's reporting of the JVM process while it is running, the process ends before the console output is finished being flushed, so it looks like the Eclipse console is buffering the output so as to minimize the impact on the running Java program.
4
u/Zarlon Feb 24 '14
From now on I'm going to start all my stack overflow answers with pure speculation
2
0
Feb 24 '14
[deleted]
1
u/Nebu Jul 20 '14
Any sane logger, when you invoke
logger.log(myStringHere);will have that log line end with a newline character, and thus there is no need for you to add a blank space or whatever.
26
u/llogiq Feb 24 '14
This is a good reminder that our code doesn't live in a frictionless vacuum. Printing to stdout does take time. Especially with threads, the effect may be more pronounced due to synchronization.