run 方法第第一步就是 创建一个StopWatch,然后启动 public ConfigurableApplicationContext run(String... args) { // 1、 StopWatch stopWatch = new StopWatch(); stopWatch.start(); // 略 ... } 1. 2. 3. 4. 5. 6. 1、new StopWatch() /*** org.springframework.util.StopWatch ***/ pub...
stopWatch.stop(); } }publicstaticStringprettyPrint() {CustomStopWatchstopWatch = threadLocal.get();if(stopWatch.currentTaskName() !=null) { stopWatch.stop(); } threadLocal.remove();returnstopWatch.prettyPrint(); }publicstaticStringprintCurrentTask() {CustomStopWatchstopWatch = threadLocal.get...
StopWatch stopWatch = new StopWatch(); stopWatch.start(); Thread.sleep(3000); stopWatch.stop(); log.info("方法执行时间:{}毫秒",stopWatch.getTime()); log.info("方法执行时间:{}秒",stopWatch.getTime(TimeUnit.SECONDS)); } } 输出 已连接到目标 VM, 地址: ''127.0.0.1:52888',传输: '...
1//创建Stopwatch实例2Stopwatch sw =newStopwatch();3//开始计时4sw.Start();5for(inti =0; i <100; i++)6{7Console.WriteLine(i);8}9//停止计时10sw.Stop();11Console.WriteLine("用时:"+ sw.ElapsedMilliseconds +"");12//重置 停止时间间隔测量,并将运行时间重置为013sw.Reset();14Console....
Stopwatch stopwatch=newStopwatch();stopwatch.Start();for(int i=0;i<10000000;i++){// 耗时操作}stopwatch.Stop();Console.WriteLine("第一个for循环操作用时:{0}ms",stopwatch.ElapsedMilliseconds);//重置 停止时间间隔测量,并将运行时间重置为0stopwatch.Reset();Console.WriteLine("运行时间重置为0:...
com.google.common.base.Stopwatch; org.apache.commons.lang3.time.StopWatch; springframework.util.StopWatch; 2.2 工具类使用 对于Spring Watch的使用很简单,直接看下代码: public void test3() throws InterruptedException { StopWatch stopWatch = new StopWatch("用户注册"); //启动任务一 stopWatch.start...
importorg.springframework.util.StopWatch;publicclassStopWatchTest{publicstaticvoidmain(String[]args)throwsInterruptedException{StopWatchstopWatch=newStopWatch("1");stopWatch.start("task1");Thread.sleep(1000);stopWatch.stop();stopWatch.start("task2");Thread.sleep(2000);stopWatch.stop();stopWatch.st...
Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Thread.Sleep(5000); // 耗时操作 stopWatch.Stop(); // 将经过的时间作为TimeSpan值 TimeSpan ts = stopWatch.Elapsed; // 格式和显示时间值 string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}-{4:000}", ts....
import org.apache.commons.lang3.time.StopWatch; import java.util.concurrent.TimeUnit; @Slf4j public class Test { public static void main(String[] args) throws InterruptedException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); ...
StopWatch支持同时记录多个任务的时间。这对于需要比较不同代码块或方法执行效率的场景非常有用。我们可以通过调用stopWatch.start(taskName)来启动一个名为taskName的任务,并在任务完成后调用stopWatch.stop(taskName)来停止计时。这样,StopWatch就会分别记录每个任务的时间。 获取计时数据 StopWatch提供了多种方法来获取...