官网地址

程序猿升级课

热爱开源,喜欢摸索


StopWatch工具类统计时间

package com.newlandframework.test;


import org.springframework.util.StopWatch;

/**
 * @Package: com.newlandframework.test
 * @Description: ${todo}
 * @author: liuxin
 * @date: 2017/8/22 下午7:03
 */
public class Main {

/*
-----------------------------------------
    ms     %     Task name
-----------------------------------------
00103  045%  读取文件
00104  046%  文件删除
00011  005%  文件拷贝
00010  004%  文件结束*/


    /**
     * 每个执行任务,占用总共时间的比例
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        org.springframework.util.StopWatch sw = new StopWatch();

        sw.start("读取文件");
        Thread.sleep(100);
        sw.stop();


        sw.start("文件删除");
        Thread.sleep(100);
        sw.stop();


        sw.start("文件拷贝");
        Thread.sleep(10);
        sw.stop();

        sw.start("文件结束");
        Thread.sleep(10);
        sw.stop();

        System.out.println(sw.prettyPrint());


        long stime = System.currentTimeMillis();
        Thread.sleep(1000);
        long etime = System.currentTimeMillis();
        System.out.println("执行时间:" + (etime - stime));
    }
}


posted @ 2017-08-28 19:15  chinesszz  阅读(122)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~