import org.springframework.util.StopWatch;
public static void main(String[] args) throws InterruptedException {
StopWatch sw = new StopWatch("测试计时工具类StopWatch");
sw.start("第一次计时");
Thread.sleep(100);
sw.stop();
sw.start("第二次计时");
Thread.sleep(200);
sw.stop();
System.out.println(sw.prettyPrint());
}
输出结果如下:
StopWatch ‘测试计时工具类StopWatch’: running time (millis) = 302
ms | % | Task name |
---|---|---|
00101 | 033% | 第一次计时 |
00201 | 067% | 第二次计时 |