org.apache.commons.lang.time.StopWatch.stop()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.apache.commons.lang.time.StopWatch.stop()方法的一些代码示例,展示了StopWatch.stop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch.stop()方法的具体详情如下:
包路径:org.apache.commons.lang.time.StopWatch
类名称:StopWatch
方法名:stop

StopWatch.stop介绍

[英]Stop the stopwatch.

This method ends a new timing session, allowing the time to be retrieved.
[中]停下秒表。
此方法结束一个新的计时会话,允许检索时间。

代码示例

代码示例来源:origin: stackoverflow.com

StopWatch stopWatch = new StopWatch("My Stop Watch");

stopWatch.start("initializing");
Thread.sleep(2000); // simulated work
stopWatch.stop();

stopWatch.start("processing");
Thread.sleep(5000); // simulated work
stopWatch.stop();

stopWatch.start("finalizing");
Thread.sleep(3000); // simulated work
stopWatch.stop();

System.out.println(stopWatch.prettyPrint());

代码示例来源:origin: stackoverflow.com

private void lapWatchAndLog( StopWatch watch, String messageForLap ) {

  watch.stop();
  LOGGER.info( String.format( "Time: [%s] %s", watch.getTime(), messageForLap ) );
  watch.reset();
  watch.start();
}

代码示例来源:origin: stackoverflow.com

float time;
protected GHResponse doInBackground( Void... v ){
  StopWatch sw = new StopWatch().start();
  GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).
  setAlgorithm(AlgorithmOptions.DIJKSTRA_BI);
  put("instructions", "false");
  GHResponse resp = hopper.route(req);
  time = sw.stop().getSeconds();
  return resp;

代码示例来源:origin: stackoverflow.com

Set<Class<?>> findAllMessageDrivenClasses() {
 final StopWatch sw = new StopWatch();
 sw.start();
 final Reflections reflections = new Reflections("org.projectx", new TypeAnnotationsScanner());
 Set<Class<?>> allMessageDrivens = reflections.getTypesAnnotatedWith(MyMessageDriven.class); // NOTE HERE
 sw.stop();
 return allMessageDrivens;
}

代码示例来源:origin: stackoverflow.com

import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.util.StopWatch;

@Aspect
public class ProfilingAspect {

  @Around("methodsToBeProfiled()")
  public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    StopWatch sw = new StopWatch(pjp.getSignature().getClass().getSimpleName());
    try {
      sw.start(pjp.getSignature().getName());
      return pjp.proceed();
    } finally {
      sw.stop();
      LogFactory.getLog(pjp.getSignature().getClass()).debug(sw.shortSummary());
    }
  }

  @Pointcut("execution(public * *.*(..))")
  public void methodsToBeProfiled(){}
}

代码示例来源:origin: stackoverflow.com

StopWatch stopWatch = new StopWatch();
stopWatch.getTime();
stopWatch.stop();
stopWatch.start();

代码示例来源:origin: david-schuler/javalanche

public void run() {
  try {
    stopWatch.start();
    Test actualtest = allTests.get(testName);
    if (actualtest == null) {
      String message = "Test not found in: " + testName
          + "\n All Tests:" + allTests;
      System.out.println(message);
      logger.warn(message);
      System.exit(0);
    }
    result.addListener(listener);
    actualtest.run(result);
  } catch (Exception e) {
    logger.debug("Cought exception from test " + e
        + " Message " + e.getMessage());
  } finally {
    stopWatch.stop();
    finished = true;
  }
}

代码示例来源:origin: stackoverflow.com

StopWatch stopWatch = new StopWatch();
stopWatch.start();
   // Do something
stopWatch.stop();
   System.out.println(stopWatch.getTotalTimeMillis());

代码示例来源:origin: org.carewebframework/org.carewebframework.ui.core

/**
 * Executes the target operation with timings.
 */
@Override
public void run() {
  watch.start();
  
  ExecutionContext.invoke(page.getId(), () -> {
    try {
      target.run(ThreadEx.this);
    } catch (Throwable e) {
      exception = e;
    }
  });
  watch.stop();
  ThreadEx.this.done();
}

代码示例来源:origin: stackoverflow.com

ApplicationContext context = new ClassPathXmlApplicationContext("path/to/applicationContext.xml");

JobLauncher launcher=(JobLauncher)context.getBean("launcher");
Job job=(Job)context.getBean("job");

//Get as many beans you want
//Now do the thing you were doing inside test method
StopWatch sw = new StopWatch();
sw.start();
launcher.run(job, jobParameters);
sw.stop();
//initialize the log same way inside main
logger.info(">>> TIME ELAPSED:" + sw.prettyPrint());

代码示例来源:origin: stackoverflow.com

stopwatch.stop();
stopwatch.start();

代码示例来源:origin: zstackio/zstack

public ShellResult run() {
  StopWatch watch = new StopWatch();
  watch.start();
  try {
    if (withSudo) {
      process.destroy();
    watch.stop();
    if (!suppressTraceLog && logger.isTraceEnabled()) {
      logger.trace(String.format("shell command[%s] costs %sms to finish", command, watch.getTime()));

代码示例来源:origin: zstackio/zstack

StopWatch watch = new StopWatch();
watch.start();
try {
  build();
  return ret;
} finally {
  watch.stop();
  if (logger.isTraceEnabled()) {
    if (script != null) {

代码示例来源:origin: naver/ngrinder

/**
 * Test method for {@link ThreadUtils#sleep(long)}.
 */
@Test
public void testSleep() {
  StopWatch watch = new StopWatch();
  watch.start();
  ThreadUtils.sleep(1000);
  watch.stop();
  assertThat(watch.getTime()).isGreaterThanOrEqualTo(1000);
  assertThat(watch.getTime()).isLessThan(3000);
}

代码示例来源:origin: stackoverflow.com

StopWatch stopwatch = new StopWatch();
stopwatch.start();
... some code...
stopwatch.stop();
long timeTaken = stopWatch.getTime()

代码示例来源:origin: stackoverflow.com

import java.util.Arrays;

public class TestStopWatch {

  public void measureTime(){

  StopWatch stopWatch = new StopWatch();

  double startTime = stopWatch.start(); //trying to call the start method in the previous class

  //code to create and sort array

    double endTime = stopWatch.stop(); //stop method in previous class

  System.out.println(getElapsedTime(startTime,endTime)); //call getElapsedtime and print

  }
}

代码示例来源:origin: stackoverflow.com

public void myMethod(){
  StopWatch stopWatch = new StopWatch();

  stopWatch.start("Task1");
  // ...
  // Do my thing
  // ...
  stopWatch.stop();
  System.out.println("Task executed in " + StopWatch.getTotalTimeSeconds() + "s");
}

代码示例来源:origin: stackoverflow.com

StopWatch stopWatch = new StopWatch("Performance Test Result");

stopWatch.start("Method 1");
doSomething1();//method to test
stopWatch.stop();

stopWatch.start("Method 2");
doSomething2();//method to test
stopWatch.stop();

System.out.println(stopWatch.prettyPrint());

代码示例来源:origin: stackoverflow.com

@Around("execution(* my.package..*.*(..))")
public Object logTime(ProceedingJoinPoint joinPoint) throws Throwable {
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  Object retVal = joinPoint.proceed();
  stopWatch.stop();
  log.info(" execution time: " + stopWatch.getTotalTimeMillis() + " ms");
  return retVal;
}

代码示例来源:origin: stackoverflow.com

import java.util.Arrays;

public class TestStopWatch {
  pubic static void main(String args[]){

    StopWatch sw=new StopWatch();

    long p=sw.start(); //trying to call the start method in the previous class

    //code to create and sort array

    long q=sw.stop(); //stop method in previous class

    System.out.println(sw.getElapsedTime((double)q,(double)p)); //call getElapsedtime and print

  }
}

相关文章