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. 【Unity|C#】基础篇(7)——属性(Property)/ 索引器(Indexer)

    [学习资料] <C#图解教程>(第6章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu.c ...

  2. linux切换普通用户遇bash-4.1解决

    1,修改vim  /etc/passwd 把对应用户的登陆环境改成,/bin/bash 2,复制配置 cp -a /etc/skel/. /home/www/ 3再次尝试su www有效

  3. Microsonf visual c++ 14+ 离线内网安装

    内网离线安装方法:先下载官方的visualcppbuildtools: <br  href=http://go.microsoft.com/fwlink/?LinkId=691126 >& ...

  4. javascript当中Function用法

    4)Function用法 例 3.4.1 <head>    <meta http-equiv="content-type" content="text ...

  5. Web API入参,响应规范

    入参绑定 入参应该定义成实体,而不是多个参数,方便扩展.[FromBody]和[FromUrl]特性也最好加上. public ActionResult<Pet> Create([From ...

  6. 【译】从 Rust 到不只是 Rust:PHP 语言领域

    From Rust to beyond: The PHP galaxy 译文 原文地址:https://mnt.io/2018/10/29/from-rust-to-beyond-the-php-ga ...

  7. Jenkins - 基于 Docker 的 Jenkins 安装

    概述 安装 Jenkins 基于 Docker 这个有点 水一发 的性质... 场景 学习 Jenkins 第一步, 当然是安装 但是 安装的方法 很多 Jenkins 是基于 Java 的 所以是个 ...

  8. Codeforces Round #620 (Div. 2)D(LIS,构造)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ io ...

  9. Equalize

    You are given two binary strings aa and bb of the same length. You can perform the following two ope ...

  10. B. Game with string 思维问题转化

    B. Game with string 思维问题转化 题意 有一个字符串 每次可以删去连续的两个同样的字符,两个人轮流删,问最后谁能赢 思路 初看有点蒙蔽,仔细看看样例就会发现其实就是一个括号匹配问题 ...