/** * <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()); }
StopWatch stopWatch = new StopWatch(); stopWatch.getTime(); stopWatch.stop(); stopWatch.start();
logger.trace(String.format("shell command[%s] costs %sms to finish", command, watch.getTime()));
/** * Log a message to persistent storage. Elapsed time since start is added. * @param message * @throws IOException */ public void instanceLog(String message) throws IOException { long elapsedMs = getStopWatch().getTime(); String displayTime = elapsedMs < 1000 ? elapsedMs + " ms" : elapsedMs / 1000 + " sec"; message = getDateTime() + " (" + displayTime + ") : " + message + "\n"; System.out.println(message); getFileOutputStream().write(message.getBytes()); }
if (logger.isTraceEnabled()) { if (script != null) { logger.trace(String.format("execute script[%s], cost time:%s", script.scriptName, watch.getTime())); } else { String cmd = StringUtils.join(CollectionUtils.transformToList(commands, new Function<String, SshRunner>() { "command: {2}\n", "cost time: {3}ms\n" ).format(hostname, port, cmd, watch.getTime()); logger.trace(info);
/** * Returns the execution time in milliseconds of the thread. * * @return long elapsed */ public long getElapsed() { return watch.getTime(); }
/** * Gets the running time, in milliseconds, of the analyser. * * @return the running time of the analyser. * @since 2.7.0 */ public long getRunningTime() { return stopWatch.getTime(); }
private synchronized void updateStats(StopWatch sw, long uploadedBytes) { totalTime += sw.getTime(); totalBytes += uploadedBytes; imageContainerSize -= uploadedBytes; if (totalTime > 0) { float averageBps = totalBytes / ((float) totalTime / 1000); timeLeft = (long) Math .ceil((imageContainerSize / averageBps) * 1000); } }
public void stop() { if (LOG.isDebugEnabled()) { stopwatch.stop(); long totalTime = stopwatch.getTime(); LOG.debug(String.format(STOP_LABEL, name, totalTime / 60000, (float) (totalTime % 60000) / 1000)); } }
public void progress() { counter.incrementAndGet(); if (counter.get() % reportInterval == 0) { long time = stopWatch.getTime() / 1000; listener.onProgress(String.format("handled [%d] in [%d]s ([%.1f] /s)", counter.get(), time, (float) counter.get() / time)); } } }
StopWatch myMapTimer = new StopWatch(); HashMap<Integer, Integer> hashMap = new HashMap<>(); myMapTimer.start(); for (int i = 0; i < numElements; i++) hashMap.put(i, i); myMapTimer.stop(); System.out.println(myMapTimer.getTime()); // time will be in milliseconds
StopWatch sw = new StopWatch(); sw.start(); // query you want to measure the time for sw.stop(); long timeInMilliseconds = sw.getTime(); System.out.println("Time in ms is: " + timeInMilliseconds ); // or maybe log it if you like?
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 stuff stopWatch.stop(); long nanos = stopWatch.getNanos(); // time in nanoseconds long millis = stopWatch.getTime(); // time in millis
StopWatch stopWatch = new StopWatch(); stopWatch.start(); ... stopWatch.suspend(); ... stopWatch.resume(); ... stopWatch.stop(): long elapsed = stopWatch.getTime();
protected int countImagesWithProcessor(PDDocument pdf) throws IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); PdfImageCounter counter = new PdfImageCounter(); for (PDPage pdPage : pdf.getPages()) { counter.processPage(pdPage); } stopWatch.stop(); int imageCount = counter.getDocumentImageCount(); log.info("Images counted: time={}s,imageCount={}", stopWatch.getTime() / 1000, imageCount); return imageCount; }
private void waitForHistoryLink(final String group, final String jobId, int waitTime) { StopWatch retryStopWatch = new StopWatch(); retryStopWatch.start(); while(!jobAdmin.isHistoryLinkPresent(group, jobId)) { if(retryStopWatch.getTime() > waitTime) fail("History link for [" + group + "#" + jobId + "] did not appear"); TimeUtils.pause(200, TimeUnit.MILLISECONDS); jobAdmin.open(); } }
void report() { boolean report = config.sendReport.get(); boolean files = config.sendFiles.get(); boolean logs = config.sendLogFile.get(); if (report) { handler.update(null, new ImportEvent.DEBUG_SEND(files, logs)); } library.notifyObservers(new ImportEvent.IMPORT_SUMMARY(sw.getTime(), handler.errorCount())); }
private void runTeraSort() throws Exception { StopWatch stopWatch = new StopWatch(); TeraSort teraSort = new TeraSort(); teraSort.setConf(controller.getJobConf()); LOG.info("Starting TeraSort"); stopWatch.start(); teraSort.run(new String[] { "input", "output" }); stopWatch.stop(); LOG.info("TeraSort took {} ms", stopWatch.getTime()); }