【java】弃用System.out.println(),迎接log
展示性能差异:
1.System.out.println()输出
package com.sxd.swapping.test; import org.junit.Test; public class LogTest { @Test public void system(){ long start = System.currentTimeMillis() ; for (int i = 0; i < 1000000; i++) { System.out.println("System.out.println输出"+i); } long time = System.currentTimeMillis() - start; System.out.println(time); } }
2. org.apache.log4j.Logger 输出
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
package com.sxd.swapping.test; import org.apache.log4j.Logger; import org.junit.Test; public class LogTest { static Logger apache_log4j = Logger.getRootLogger(); @Test public void system(){ long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { apache_log4j.error("apache_log4j输出"+i); } long time = System.currentTimeMillis()-start; apache_log4j.info(time); } }
3. java.util.logging.Logger 输出
package com.sxd.swapping.test; import org.junit.Test; import java.util.logging.Logger; public class LogTest { static Logger util_logging = Logger.getLogger(""); @Test public void system(){ long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { util_logging.info("util_logging输出"+i); } long time = System.currentTimeMillis()-start; util_logging.info(String.valueOf(time)); } }