java记录方法计时工具类StopWatch

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% 第二次计时
发布了10 篇原创文章 · 获赞 3 · 访问量 174

猜你喜欢

转载自blog.csdn.net/qq_40016813/article/details/103123141