zoukankan      html  css  js  c++  java
  • 【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));
        }
    }
  • 相关阅读:
    数据结构 trie 树 入门练手 POJ 3630 Phone List
    回溯法求 1~n 的排列
    POJ 1988 Cube Stacking (并查集,节点到根节点的距离题目)
    Ubuntu下的截图软件
    git使用方法
    在Linux下安装ADT
    在Linux下安装Android SDK
    在Linux下安装Java JDK
    研发项目风险因素差异性
    关于C#的partial修饰符
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/9646802.html
Copyright © 2011-2022 走看看