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% | 第二次計時 |