简体   繁体   English

SYSO(System.out.println())的作用是什么?

[英]What is effect of SYSO (System.out.println())?

What is the effect of SYSO - System.out.println() ? 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? 如果我的计算机正在执行一项大型任务,例如从数据库中提取2十万赫兹(约2,000,000条)记录到文件中,那么SYSO是否会影响执行时间?

Of course it affects it. 当然会影响它。 Every operation comes with a cost. 每次操作都会带来成本。 Writing to system out is IO, and comes with a non-negligible cost. 写入系统是IO,而且成本不可忽略。 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. 要知道你的程序效果确切,有没有其他的解决方案比基准:有和无的println调用运行程序,并测量它需要两个版本的时间,或使用一个分析器。

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. 您应该使用一个日志记录框架(例如slf4j,log4j或Java util日志记录),该框架将允许各种输出(sysout,file等),并且还可以通过仅更改a的某些属性来停用输出日志。配置文件。

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. 例如,当程序正在打印时,实际上看着控制台通常会使它确实变慢,但是当您最小化控制台窗口时,它会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM