package com.example.dyreportapi.util;
import org.springframework.util.StopWatch;
/**
* @Author:Kevin
* @Date:2023/8/17 10:28
*/
public class StopWatchTest {
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch("字符串操作时间统计");
stopWatch.start("统计字符串长度");
String str = "hello world";
int len = str.length();
stopWatch.stop();
System.out.println("task count:" + stopWatch.getTaskCount());
System.out.println("last task name:" + stopWatch.getLastTaskName());
System.out.println("total time:" + stopWatch.getTotalTimeMillis() + " ms");
System.out.println("last task time:" + stopWatch.getLastTaskTimeMillis() + " ms");
stopWatch.start("将字符串转换成大写");
String upper = str.toUpperCase();
stopWatch.stop();
System.out.println("task count:" + stopWatch.getTaskCount());
System.out.println("last task name:" + stopWatch.getLastTaskName());
System.out.println("total time:" + stopWatch.getTotalTimeMillis() + " ms");
System.out.println("last task time:" + stopWatch.getLastTaskTimeMillis() + " ms");
stopWatch.start("将字符串转换成小写");
String lower = str.toLowerCase();
stopWatch.stop();
System.out.println("task count:" + stopWatch.getTaskCount());
System.out.println("last task name:" + stopWatch.getLastTaskName());
System.out.println("total time:" + stopWatch.getTotalTimeMillis() + " ms");
System.out.println("last task time:" + stopWatch.getLastTaskTimeMillis() + " ms");
}
}
StopWatch 统计时间
于 2023-08-17 10:40:04 首次发布