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());
StopWatch stopWatch = new StopWatch(); long time = stopWatch.measureAction(() - > {/* Measure stuff here */});
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 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 } }
protected ScanResult matchForPatterns(final BufferedReader reader, final Date date) throws IOException { LOGGER.debug("start matching for patterns"); final StopWatch sw = new StopWatch(); sw.start(); final Map<String, PatternMatchSet> results = match(reader, date); LOGGER.debug("results found: {}", results.size()); return new DefaultScanResult(scanItem, results.values(), Lists.<PropertyScanResult>newArrayList(), sw.getTime()); } }
StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Do something stopWatch.stop(); System.out.println(stopWatch.getTotalTimeMillis());
/** * <p> * Gets a summary of the time that the stopwatch recorded as a string. * </p> * * <p> * The format used is ISO8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>. * </p> * * @return the time as a String */ public String toString() { return DurationFormatUtils.formatDurationHMS(getTime()); }
@PostConstruct public void createIndex() { StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { for (Class<?> classToBeIndexed : CLASSES_TO_BE_INDEXED) { indexClass(classToBeIndexed); } } finally { stopWatch.stop(); log.info("Indexed {} in {}", Arrays.toString(CLASSES_TO_BE_INDEXED), stopWatch.toString()); } }
@Override public long getLag() { // Periodically cache the end offset if(endOffset == null || endOffsetWatch.getTime() > END_OFFSET_REFRESH_MS_DEFAULT) { Map<TopicPartition, Long> offsets = consumer.endOffsets(Collections.singletonList(new TopicPartition(topicName, 0))); endOffset = offsets.get(new TopicPartition(topicName, 0)); endOffsetWatch.reset(); endOffsetWatch.start(); } // Because the end offset is only updated periodically, it's possible to see negative lag. Send 0 instead. long lag = endOffset - (getCurrentOffset() == null ? 0 : getCurrentOffset()); return lag < 0 ? 0 : lag; }
org.apache.commons.lang.time.StopWatch sw = new org.apache.commons.lang.time.StopWatch(); System.out.println("getEventFilterTreeData :: Start Time : " + sw.getTime()); sw.start(); // Method execution code sw.stop(); System.out.println("getEventFilterTreeData :: End Time : " + sw.getTime());
public void stopStopWatch() throws IOException { getStopWatch().stop(); instanceLog("STOP"); }
public PerformanceLog(String startMessage) throws IOException { getStopWatch().start(); instanceLog("START: " + startMessage); }
public class SWTest { public static void main(String[] args) { StopWatch stopWatch = new StopWatch(); doSomething(); LOGGER.debug("Execution took in seconds: ", (stopWatch.getElapsedTime()); } }