Is this something common to all programming languages? Doing multiple print followed by a println seems faster but moving everything to a string and just printing that seem
println
is not slow, it's the underlying PrintStream
that is connected with the console, provided by the hosting operating system.
You can check it yourself: compare dumping a large text file to the console with piping the same textfile into another file:
cat largeTextFile.txt
cat largeTextFile.txt > temp.txt
Reading and writing are similiar and proportional to the size of the file (O(n)), the only difference is, that the destination is different (console compared to file). And that's basically the same with System.out
.
The underlying OS operation (displaying chars on a console window) is slow because