List of usage examples for org.apache.commons.lang3.time DurationFormatUtils formatDuration
public static String formatDuration(final long durationMillis, final String format)
Formats the time gap as a string, using the specified format, and padding with zeros.
This method formats durations using the days and lower fields of the format pattern.
From source file:io.anserini.util.SearchTimeUtil.java
public static void main(String[] args) throws IOException, ParseException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { if (args.length != 1) { System.err.println("Usage: SearchTimeUtil <indexDir>"); System.err.println("indexDir: index directory"); System.exit(1);// w ww .j a v a 2 s .co m } String[] topics = { "topics.web.1-50.txt", "topics.web.51-100.txt", "topics.web.101-150.txt", "topics.web.151-200.txt", "topics.web.201-250.txt", "topics.web.251-300.txt" }; SearchWebCollection searcher = new SearchWebCollection(args[0]); for (String topicFile : topics) { Path topicsFile = Paths.get("src/resources/topics-and-qrels/", topicFile); TopicReader tr = (TopicReader) Class.forName("io.anserini.search.query." + "Webxml" + "TopicReader") .getConstructor(Path.class).newInstance(topicsFile); SortedMap<Integer, String> queries = tr.read(); for (int i = 1; i <= 3; i++) { final long start = System.nanoTime(); String submissionFile = File.createTempFile(topicFile + "_" + i, ".tmp").getAbsolutePath(); RerankerCascade cascade = new RerankerCascade(); cascade.add(new IdentityReranker()); searcher.search(queries, submissionFile, new BM25Similarity(0.9f, 0.4f), 1000, cascade); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); System.out.println(topicFile + "_" + i + " search completed in " + DurationFormatUtils.formatDuration(durationMillis, "mm:ss:SSS")); } } searcher.close(); }
From source file:io.anserini.IndexerCW09B.java
public static void main(String[] args) throws IOException, InterruptedException { Args clArgs = new Args(args); final String dataDir = clArgs.getString("-dataDir"); final String indexPath = clArgs.getString("-indexPath"); final int numThreads = clArgs.getInt("-threadCount"); clArgs.check();//from ww w . j a va 2 s . c o m Date start = new Date(); IndexerCW09B indexer = new IndexerCW09B(dataDir, indexPath); int numIndexed = indexer.indexWithThreads(numThreads); System.out.println("Total " + numIndexed + " documents indexed in " + DurationFormatUtils.formatDuration(new Date().getTime() - start.getTime(), "HH:mm:ss")); }
From source file:io.anserini.search.SearchWebCollection.java
public static void main(String[] args) throws Exception { SearchArgs searchArgs = new SearchArgs(); CmdLineParser parser = new CmdLineParser(searchArgs, ParserProperties.defaults().withUsageWidth(90)); try {/*from ww w . j a v a2s . c om*/ parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: SearchWebCollection" + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } LOG.info("Reading index at " + searchArgs.index); Directory dir; if (searchArgs.inmem) { LOG.info("Using MMapDirectory with preload"); dir = new MMapDirectory(Paths.get(searchArgs.index)); ((MMapDirectory) dir).setPreload(true); } else { LOG.info("Using default FSDirectory"); dir = FSDirectory.open(Paths.get(searchArgs.index)); } Similarity similarity = null; if (searchArgs.ql) { LOG.info("Using QL scoring model"); similarity = new LMDirichletSimilarity(searchArgs.mu); } else if (searchArgs.bm25) { LOG.info("Using BM25 scoring model"); similarity = new BM25Similarity(searchArgs.k1, searchArgs.b); } else { LOG.error("Error: Must specify scoring model!"); System.exit(-1); } RerankerCascade cascade = new RerankerCascade(); boolean useQueryParser = false; if (searchArgs.rm3) { cascade.add(new Rm3Reranker(new EnglishAnalyzer(), FIELD_BODY, "src/main/resources/io/anserini/rerank/rm3/rm3-stoplist.gov2.txt")); useQueryParser = true; } else { cascade.add(new IdentityReranker()); } FeatureExtractors extractors = null; if (searchArgs.extractors != null) { extractors = FeatureExtractors.loadExtractor(searchArgs.extractors); } if (searchArgs.dumpFeatures) { PrintStream out = new PrintStream(searchArgs.featureFile); Qrels qrels = new Qrels(searchArgs.qrels); cascade.add(new WebCollectionLtrDataGenerator(out, qrels, extractors)); } Path topicsFile = Paths.get(searchArgs.topics); if (!Files.exists(topicsFile) || !Files.isRegularFile(topicsFile) || !Files.isReadable(topicsFile)) { throw new IllegalArgumentException( "Topics file : " + topicsFile + " does not exist or is not a (readable) file."); } TopicReader tr = (TopicReader) Class .forName("io.anserini.search.query." + searchArgs.topicReader + "TopicReader") .getConstructor(Path.class).newInstance(topicsFile); SortedMap<Integer, String> topics = tr.read(); final long start = System.nanoTime(); SearchWebCollection searcher = new SearchWebCollection(searchArgs.index); searcher.search(topics, searchArgs.output, similarity, searchArgs.hits, cascade, useQueryParser, searchArgs.keepstop); searcher.close(); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); LOG.info("Total " + topics.size() + " topics searched in " + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss")); }
From source file:io.anserini.index.IndexClueWeb09b.java
public static void main(String[] args) throws IOException, InterruptedException { IndexArgs indexArgs = new IndexArgs(); CmdLineParser parser = new CmdLineParser(indexArgs, ParserProperties.defaults().withUsageWidth(90)); try {//from w w w . j a v a 2s. c om parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: IndexClueWeb09b" + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } final long start = System.nanoTime(); IndexClueWeb09b indexer = new IndexClueWeb09b(indexArgs.input, indexArgs.index); indexer.setPositions(indexArgs.positions); indexer.setOptimize(indexArgs.optimize); indexer.setDocLimit(indexArgs.doclimit); LOG.info("Index path: " + indexArgs.index); LOG.info("Threads: " + indexArgs.threads); LOG.info("Positions: " + indexArgs.positions); LOG.info("Optimize (merge segments): " + indexArgs.optimize); LOG.info("Doc limit: " + (indexArgs.doclimit == -1 ? "all docs" : "" + indexArgs.doclimit)); LOG.info("Indexer: start"); int numIndexed = indexer.indexWithThreads(indexArgs.threads); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); LOG.info("Total " + numIndexed + " documents indexed in " + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss")); }
From source file:io.anserini.search.SearchCollection.java
public static void main(String[] args) throws Exception { SearchArgs searchArgs = new SearchArgs(); CmdLineParser parser = new CmdLineParser(searchArgs, ParserProperties.defaults().withUsageWidth(90)); try {//from w w w.j a v a 2 s . com parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: SearchCollection" + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } final long start = System.nanoTime(); SearchCollection searcher = new SearchCollection(searchArgs); int numTopics = searcher.runTopics(); searcher.close(); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); LOG.info("Total " + numTopics + " topics searched in " + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss")); }
From source file:com.fanniemae.ezpie.common.DateUtilities.java
public static String elapsedTime(long start, long end) { long elapsed = Math.abs(end - start); String elapsedPretty;/*from ww w . j a va 2 s .c o m*/ if (elapsed < 60000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "s.S' seconds'"); } else if (elapsed < 3600000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "m' minutes' s.S' seconds'"); } else if (elapsed < 86400000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "H' hours' m' minutes' s.S' seconds'"); } else { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "d' days' H' hours' m' minutes' s.S' seconds'"); } // Make days/hours/minutes singular if just one unit. if (elapsedPretty.startsWith("1 days ")) elapsedPretty = elapsedPretty.replace("1 days ", "1 day "); if (elapsedPretty.contains(" 1 hours ")) elapsedPretty = elapsedPretty.replace(" 1 hours ", " 1 hour "); if (elapsedPretty.contains(" 1 minutes ")) elapsedPretty = elapsedPretty.replace(" 1 minutes ", " 1 minute "); if (end - start < 0) { return "Negative " + elapsedPretty; } return elapsedPretty; }
From source file:com.fanniemae.ezpie.common.DateUtilities.java
public static String elapsedTimeShort(long start, long end) { long elapsed = Math.abs(end - start); String elapsedPretty;// w w w . ja va2 s . c o m if (elapsed < 60000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "s.S's'"); } else if (elapsed < 3600000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "m'm' s.S's'"); } else if (elapsed < 86400000L) { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "H'h' m'm' s.S's'"); } else { elapsedPretty = DurationFormatUtils.formatDuration(elapsed, "d'd' H'h' m'm' s.S's'"); } if (end - start < 0) { return "Negative " + elapsedPretty; } return elapsedPretty; }
From source file:com.teradata.tempto.internal.listeners.ProgressLoggingListener.java
private void logTestEnd(String outcome) { long executionTime = System.currentTimeMillis() - testStartTime; LOGGER.info("{} / took {}", outcome, DurationFormatUtils.formatDuration(executionTime, "m' minutes and 's' seconds'")); }
From source file:com.neophob.sematrix.cli.PixConClientJmx.java
/** * // w w w .j av a 2 s . com * @param mbsc * @throws Exception */ private static void printJmxStatus(MBeanServerConnection mbsc) throws Exception { ObjectName mbeanName = new ObjectName(PixelControllerStatus.JMX_BEAN_NAME); PixelControllerStatusMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, PixelControllerStatusMBean.class, true); // print general status information System.out.println("\nGeneric:"); System.out.printf("%-25s: %s\n", "server version", mbeanProxy.getVersion()); System.out.printf("%-25s: %3.3f (%s of configured fps: %2.0f)\n", "current fps", mbeanProxy.getCurrentFps(), PERCENT_FORMAT.format(mbeanProxy.getCurrentFps() / mbeanProxy.getConfiguredFps()), mbeanProxy.getConfiguredFps()); System.out.printf("%-25s: %d\n", "frame count", mbeanProxy.getFrameCount()); System.out.printf("%-25s: %s\n", "running since", DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - mbeanProxy.getStartTime())); // print average timing information System.out.println("\nThe following average times have been collected during the last " + DurationFormatUtils.formatDuration(mbeanProxy.getRecordedMilliSeconds(), "ss.SSS") + " seconds:"); for (TimeMeasureItemGlobal valueEnum : TimeMeasureItemGlobal.values()) { System.out.printf(" %-22s: %3.3fms\n", valueEnum.getReadableName(), mbeanProxy.getAverageTime(valueEnum)); } // print output specific timing information for (int output = 0; output < mbeanProxy.getNumberOfOutputs(); output++) { System.out.println("\nOuput-specific average times for output #" + (output + 1) + ": " + mbeanProxy.getOutputType(output).getReadableName()); for (TimeMeasureItemOutput outputValueEnum : TimeMeasureItemOutput.values()) { System.out.printf(" %-22s: %3.3fms\n", outputValueEnum.getReadableName(), mbeanProxy.getOutputAverageTime(output, outputValueEnum)); } } }
From source file:com.serphacker.serposcope.models.base.Run.java
public String getDurationFormated() { return DurationFormatUtils.formatDuration(getDurationMs(), "HH:mm:ss"); }