背景
今天使用Intellij插件 - PMD(这里不对此插件的使用进行讲解)分析代码时出现了“System.out.println is used”的问题,于是特地百度了一下。
原文:https://blog.csdn.net/linzhiqiang0316/article/details/102692496
测试
@Test
public void testSystem() {
long start1 = System.currentTimeMillis();
int key = 0;
for (int i = 0; i < 100000; i++) {
key = i;
System.out.println("i:" + i);
}
long end1 = System.currentTimeMillis();
System.out.println("有输出语句的耗时:" + (end1 - start1));
long start2 = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
key = i;
}
long end2 = System.currentTimeMillis();
System.out.println("无输出语句的耗时:" + (end2 - start2));
}
...
有输出语句的耗时:2369
无输出语句的耗时:1
总结
在性能要求较高的项目中,应慎用System.out.println()!!!