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));
}
}
StopWatch工具类统计时间
原创
©著作权归作者所有:来自51CTO博客作者西魏陶渊明的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:重入锁和自旋锁
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
计时器工具 StopWatch
StopWatch,它可以用来对程序中代码块,或者方法进行计时,并且支持多阶段计时,以及阶段时间占比等统计,使用起来代码比较简洁,轻量。
java spring 计时器 StopWatch 执行时间 -
StopWatch(秒表)实现计时
场景统计某段代码的执行时
System Math 执行时间 -
Stopwatch(计时类)用法
Stopwatch(计时类)用法……
sed i++ 计时类 运行时间 时间间隔