统计输出总耗时
代码语言:javascript复制StopWatch sw = new StopWatch();
sw.start();
// long task simulation
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
以优雅的格式打出所有任务的耗时以及占比
代码语言:javascript复制 StopWatch sw = new StopWatch();
sw.start("A");
Thread.sleep(500);
sw.stop();
sw.start("B");
Thread.sleep(300);
sw.stop();
sw.start("C");
Thread.sleep(200);
sw.stop();
System.out.println(sw.prettyPrint());
参考
https://mp.weixin.qq.com/s/RNsuFaONmruEnyJGKad5sA