1.测试
package com.example.demo;
import org.junit.Test;
import org.springframework.util.StopWatch;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class StopWatchTest{
@Test
public void testStopWatch() throws InterruptedException {
StopWatch stopWatch = new StopWatch();
stopWatch.start("任务一");
Thread.sleep(1000);
stopWatch.stop();
stopWatch.start("任务二");
Thread.sleep(2000);
stopWatch.stop();
stopWatch.start("任务三");
Thread.sleep(3000);
stopWatch.stop();
log.debug(stopWatch.prettyPrint());
}
}
2.输出结果
14:20:24.926 [main] DEBUG com.example.demo.StopWatchTest - StopWatch '': running time (millis) = 6002
-----------------------------------------
ms % Task name
-----------------------------------------
01000 017% 任务一
02001 033% 任务二
03001 050% 任务三