What is effect of SYSO (System.out.println())?
Asked Answered
E

2

1

What is the effect of SYSO - System.out.println()? If my computer is executing a large job such as fetching 2 Lakhs (approximately 2,000,000) records from a database to a file, does SYSO affect the execution time?

Edyth answered 10/6, 2012 at 7:13 Comment(1)
You should profile your program. Prepare 2 version one with and one without SYSO. Run them both multiple times. Compare the average run times. Report back your results.Beefwood
B
7

Of course it affects it. Every operation comes with a cost. Writing to system out is IO, and comes with a non-negligible cost. To know the exact effect on your program, there's no other solution than benchmarking: run the program with and without the println calls, and measure the time it takes for both versions, or use a profiler.

You should use a logging framework (like slf4j, log4j or java util logging), which would allow for various kinds of outputs (sysout, file, etc.), and which would also allow deactivating the output log by just changing some property in a config file.

Blondellblondelle answered 10/6, 2012 at 7:18 Comment(3)
Indeed, if the System.out stream is connected to a GUI-based console, you've got the cost of redrawing the screen each time data gets flushed.War
@pst: we don't know if the goal of the OP is to reduce the time of an existing program, or if it's a general question. I've edited my answer to at least mention logging, which should be preferred over sysout anyway.Blondellblondelle
@pst: OK, that was obvious to me, but the fact that it affects perfromance was also obvious, so I added a bit about measuring.Blondellblondelle
C
1

The effect on performance is very much dependent on how fast the recipient (usually a console or a file system) can read from the stream and how big of a buffer there is. For example, actually looking at the console, as the program is printing, usually makes it really slow, but when you minimize the console window it's faster.

Consols answered 3/9, 2013 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.