Refine search
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());
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;
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; }
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(){} }
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; } }
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());
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 } }
@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; }
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 } }