package com.example.stopwatch;

import org.springframework.util.StopWatch;

public class TestStopWatch {
private void test() throws InterruptedException {
StopWatch sw = new StopWatch(); sw.start("起床");
Thread.sleep(1000);
sw.stop(); sw.start("洗漱");
Thread.sleep(2000);
sw.stop(); sw.start("锁门");
Thread.sleep(500);
sw.stop(); System.out.println(sw.prettyPrint());
System.out.println(sw.getTotalTimeMillis());
System.out.println(sw.getLastTaskName());
System.out.println(sw.getLastTaskInfo());
System.out.println(sw.getTaskCount());
} public static void main(String []argv) throws InterruptedException {
TestStopWatch testStopWatch = new TestStopWatch();
testStopWatch.test();
}
}

结果

1
2
3
4
5
6
7
8
9
10
11
12
StopWatch '': running time (millis) = 3518
-----------------------------------------
ms     %     Task name
-----------------------------------------
00998  028%  起床
02020  057%  洗漱
00500  014%  锁门
 
3518
锁门
org.springframework.util.StopWatch$TaskInfo@5b2133b1
3

stopWatch 用法的更多相关文章

  1. 监控代码运行时长 -- StopWatch用法例程

    在.net环境下,精确的测量出某段代码运行的时长,在网络通信.串口通信以及异步操作中很有意义.现在做了简单的总结.具体代码如下: (1).首先 using System.Diagnostics; (2 ...

  2. Spring 中StopWatch用法

    背景 有时我们在做开发的时候需要记录每个任务执行时间,或者记录一段代码执行时间,最简单的方法就是打印当前时间与执行完时间的差值,然后这样如果执行大量测试的话就很麻烦,并且不直观,如果想对执行的时间做进 ...

  3. spring StopWatch用法

    背景 有时我们在做开发的时候需要记录每个任务执行时间,或者记录一段代码执行时间,最简单的方法就是打印当前时间与执行完时间的差值,然后这样如果执行大量测试的话就很麻烦,并且不直观,如果想对执行的时间做进 ...

  4. spring计时工具类stopwatch用法

    public class Test { public static void main(String[] args) { StopWatch stopWatch = new StopWatch(); ...

  5. StopWatch的用法

    在学习spring的时候,看到关于统计时间的类,比较好奇,就记录下来,以便以后用到可以直接使用 org.springframework.util.StopWatch StopWatch该类在统计时间的 ...

  6. C#基础系列——多线程的常见用法详解

    前言:前面几节分别介绍了下C#基础技术中的反射.特性.泛型.序列化.扩展方法.Linq to Xml等,这篇跟着来介绍下C#的另一基础技术的使用.最近项目有点紧张,所以准备也不是特别充分.此篇就主要从 ...

  7. Stopwatch 类

    Stopwatch 为计时器的实现. 主要属性方法 属性和方法 说明 static GetTimestamp() 如果Stopwatch使用高分辨率的性能计数器,则返回该计数器的当前值:如果Stopw ...

  8. Stopwatch 和TimeSpan介绍【转】

    1.使用 Stopwatch 类 (System.Diagnostics.Stopwatch) Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 S ...

  9. C#中各种计时器 Stopwatch、TimeSpan

    1.使用 Stopwatch 类 (System.Diagnostics.Stopwatch)Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 St ...

随机推荐

  1. vba工程密码清除

    EXCEL vba工程密码破解 方法一:这种方法实际是避开VBA工程密码验证,即骗vba编辑器,该密码输入成功,请求放行.不管他是破解还是欺骗 能达到我们的目的角开就行________________ ...

  2. @Html.DropDownList()的四种用法及自定义DropDownList扩展

    https://blog.csdn.net/xiaouncle/article/details/82856982

  3. php设计模式之适配器模式实例代码

    <?php header("Content-type:text/html;charset=utf-8"); // 适配器模式 /** * 查看天气接口 */ class Ti ...

  4. LED Decorative Light Supplier - LED Environmental Decorative Lighting Application

    Creating ambient lighting in the home can bridge the gap between the internal world and the outside ...

  5. jsp连接数据库增删改查

    一,创建表 二.将jar包复制导入到lib文件夹下 三.创建工具包连接数据库 package com.bill.util; import java.sql.Connection; import jav ...

  6. telnet不起作用

    1.出现 'telnet' 不是内部或外部命令,也不是可运行的程序或批处理文件. 原因:因为本机的Telnet客户端默认是关闭的,所以我们要手动打开 解决方案:打开控制面板–>程序–>打开 ...

  7. Junit +cucumber 运行报错 initiallizationError

    step1: 访问 https://search.maven.org/  搜索下载相关jar包 step2: 访问 http://maven.outofmemory.cn/info.cukes/cuc ...

  8. Iris路由和路由组

    package main import ( "github.com/kataras/iris" "github.com/kataras/iris/context" ...

  9. Eqaulize Prices

    There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...

  10. 百炼OJ - 1007 - DNA排序

    题目链接:http://bailian.openjudge.cn/practice/1007 #include<stdio.h> #include<algorithm> usi ...