StopWatch需要依赖spring-core这个jar包
主要作用
记录开始时间点
记录结束时间点
输出执行时间及各个时间段的占比
public static void main(String[] args) {
StopWatch sw = new StopWatch("test");
sw.start("task1");
// do something
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sw.stop();
sw.start("task2");
// do something
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sw.stop();
System.out.println("~~~~~~~~~~~~~~~~~");
System.out.println(sw.prettyPrint());
}