Console
As some test: printing to System.out the result is:
Printing line : #0
.
.
.
Printing line : #14997
Printing line : #14998
Printing line : #14999
System.out took: 238ms
- Test #1:
238ms
- Test #2:
235ms
- Test #3:
251ms
- Test #4:
210ms
- Test #5:
172ms
- Test #6:
268ms
new Stream
And using a new Stream
the result is:
Printing line : #0
.
.
.
Printing line : #14996
Printing line : #14997
Printing line : #14998
Printing line : #14999
System.out with new stream took: 220ms
- Test #1:
220ms
- Test #2:
219ms
- Test #3:
222ms
- Test #4:
220ms
- Test #5:
223ms
- Test #6:
250ms
Code
try {
System.setOut(new PrintStream(new FileOutputStream("C:\\TMP\\logs.log")));
long startTime = Calendar.getInstance().getTimeInMillis();
for (int a=0;a<15000;a++) {
System.out.println("Printing line : #"+a);
}
long elapsedTime = (Calendar.getInstance().getTimeInMillis() - startTime);
System.out.println("System.out took: " + elapsedTime + "ms");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
As you see the difference in speed is not a even a "deal", What I didn't check was the performance (Disk I/O, Memory and CPU) using those methods.
But if you ask me about what i Think, i will tell that the result will be something like the speed test that we just performed... For my logs in any application i code, i use Log4J ( http://logging.apache.org/log4j/1.2/index.html ) to log anything i want and you can set the level of loggin you want (debug, info, error, etc)