log4j配置参考:
http://javapub.iteye.com/blog/866664
循环代码如下
system循环。 耗时,11691
package com; public class TestStaticClassMain { public static void main(String[] args) { long start = System.currentTimeMillis() ; for (int i = 0; i < 1000000; i++) { System.out.println("Syso输出"+i); } long time = System.currentTimeMillis() - start; System.out.println(time); } }log4j循环。 耗时:3154
package com; import org.apache.log4j.Logger; public class TestStaticClass { static Logger _log = Logger.getRootLogger(); public static void main(String ... arg0){ long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { _log.error("log输出"+i); } long time = System.currentTimeMillis()-start; _log.info("所用时间" + time); } }
而且,用system在多线程也会有影响。所以,输出最好是用log.
待会 补充 测试 java.util.logging.Logger; 的文章。
时间太慢了。
时间是73554
package com; import java.util.logging.Logger; public class LoggerClass { static Logger log = Logger.getLogger(""); public static void main(String ... arg0){ long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { log.info("循环"+i+"次"); } long time = System.currentTimeMillis()-start; log.info("时间是"+time); } }