What's the fastest way to output a string to system out?

前端 未结 5 1782
南旧
南旧 2020-12-04 22:58

I\'m doing something like this:

for (int i = 0; i < 100000; i++) {
   System.out.println( i );
}

Basically, I compute an integer and out

5条回答
  •  余生分开走
    2020-12-04 23:24

    The slowest part of writing to System.out is the time taken to display what you are writing. i.e. for every line you write the computer has to turn the information into pixels using a font and scroll a whole line. This is much more work than whatever you are likely to be doing to display the text.

    You can speed up writing to the console by

    • writing less (usually the best idea)
    • writing to a file instead (This can be 5-10x faster)

提交回复
热议问题