SYSO (System.out.println()) 的作用是什么? [英] What is effect of SYSO (System.out.println())?

查看:36
本文介绍了SYSO (System.out.println()) 的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SYSO - System.out.println() 的作用是什么?如果我的计算机正在执行一项大型作业,例如从数据库中提取 20 万(约 2,000,000)条记录到文件,SYSO 会影响执行时间吗?

解决方案

当然会影响它.每一次手术都是有代价的.写入系统输出是 IO,并且具有不可忽略的成本.要了解对您的程序的确切影响,除了基准测试之外别无他法:运行程序时使用和不使用 println 调用,并测量两个版本所用的时间,或者使用分析器.>

您应该使用日志框架(如 slf4j、log4j 或 java util logging),它允许各种输出(sysout、文件等),并且还允许通过更改一些输出日志来停用输出日志配置文件中的属性.

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?

解决方案

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.

这篇关于SYSO (System.out.println()) 的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆