Spring中的StopWatch記錄操作時間代碼實例
StopWatch記錄操作時間
說明
spring-framework提供的一個StopWatch類可以做類似任務執(zhí)行時間控制,也就是封裝了一個對開始時間,結束時間記錄操作的Java類。
示例
start開始記錄,stop停止記錄,然后通過StopWatch的prettyPrint方法,可直觀的輸出代碼執(zhí)行耗時,以及執(zhí)行時間百分比。
public class TestStopWatch { public static void main(String[] args) throws InterruptedException { StopWatch sw = new StopWatch(); sw.start("doSomething1"); Thread.sleep(200); sw.stop(); sw.start("doSomething2"); Thread.sleep(200); sw.stop(); sw.start("doSomething3"); Thread.sleep(200); sw.stop(); System.out.println(sw.prettyPrint()); } }
控制臺打印結果如下
StopWatch '': running time = 613210100 ns
---------------------------------------------
ns % Task name
---------------------------------------------
201980400 033% doSomething1
201809600 033% doSomething2
209420100 034% doSomething3
Process finished with exit code 0
到此這篇關于Spring中的StopWatch記錄操作時間代碼實例的文章就介紹到這了,更多相關StopWatch記錄操作時間內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Spring Boot mybatis-config 和 log4j 輸出sql 日志的方式
這篇文章主要介紹了Spring Boot mybatis-config 和 log4j 輸出sql 日志的方式,本文通過實例圖文相結合給大家介紹的非常詳細,需要的朋友可以參考下2021-07-07IDEA2023常用配置指南(JDK/系統(tǒng)設置等常用配置)
idea很強大,但是初次安裝默認的有很多設置并不是滿足我們開發(fā)的需要,下面這篇文章主要給大家介紹了關于IDEA2023常用配置(JDK/系統(tǒng)設置等常用配置)的相關資料,需要的朋友可以參考下2023-12-12