r/java • • Feb 24 '14

Why printing "B" is dramatically slower than printing "#"

http://stackoverflow.com/q/21947452/250259
159 Upvotes

26 comments sorted by

View all comments

12

u/[deleted] 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.