com.google.common.base.Stopwatch.toString()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(125)

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

Stopwatch.toString介绍

[英]Returns a string representation of the current elapsed time.
[中]返回当前运行时间的字符串表示形式。

代码示例

代码示例来源:origin: ben-manes/caffeine

/** Assembles an aggregated report. */
@Override
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
protected String assemble(List<PolicyStats> results) {
 String[][] data = new String[results.size()][headers().length];
 for (int i = 0; i < results.size(); i++) {
  PolicyStats policyStats = results.get(i);
  data[i] = new String[] {
    policyStats.name(),
    String.format("%.2f %%", 100 * policyStats.hitRate()),
    String.format("%,d", policyStats.hitCount()),
    String.format("%,d", policyStats.missCount()),
    String.format("%,d", policyStats.requestCount()),
    String.format("%,d", policyStats.evictionCount()),
    String.format("%.2f %%", 100 * policyStats.admissionRate()),
    steps(policyStats),
    policyStats.stopwatch().toString()
  };
 }
 return FlipTable.of(headers(), data);
}

代码示例来源:origin: querydsl/querydsl

public static void run(String label, Benchmark benchmark) throws Exception {
  // warmup
  benchmark.run(WARMUP);
  System.err.print("- ");
  // run garbage collection
  System.gc();
  System.err.print("- ");
  // perform timing
  Stopwatch stopwatch = Stopwatch.createStarted();
  benchmark.run(BENCHMARK);
  System.err.println(label + " " + stopwatch.stop().toString());
}

代码示例来源:origin: google/guava

public void testToString() {
 stopwatch.start();
 assertEquals("0.000 ns", stopwatch.toString());
 ticker.advance(1);
 assertEquals("1.000 ns", stopwatch.toString());
 ticker.advance(998);
 assertEquals("999.0 ns", stopwatch.toString());
 ticker.advance(1);
 assertEquals("1.000 \u03bcs", stopwatch.toString());
 ticker.advance(1);
 assertEquals("1.001 \u03bcs", stopwatch.toString());
 ticker.advance(8998);
 assertEquals("9.999 \u03bcs", stopwatch.toString());
 stopwatch.reset();
 stopwatch.start();
 ticker.advance(1234567);
 assertEquals("1.235 ms", stopwatch.toString());
 stopwatch.reset();
 stopwatch.start();
 ticker.advance(5000000000L);
 assertEquals("5.000 s", stopwatch.toString());
 stopwatch.reset();
 stopwatch.start();
 ticker.advance((long) (1.5 * 60 * 1000000000L));
 assertEquals("1.500 min", stopwatch.toString());
 stopwatch.reset();
 stopwatch.start();
 ticker.advance((long) (2.5 * 60 * 60 * 1000000000L));
 assertEquals("2.500 h", stopwatch.toString());
 stopwatch.reset();

代码示例来源:origin: sonatype/nexus-public

/**
 * Get elapsed time as a string so it can be included in logs
 */
public String getElapsed() {
 return elapsed.toString();
}

代码示例来源:origin: kframework/k

@Override
public String toString() {
  return stopwatch.get().toString();
}

代码示例来源:origin: codeine-cd/codeine

private static String readdir() {
  StringBuilder sb = new StringBuilder();
  Stopwatch s = Stopwatch.createStarted();
  sb.append(new File(dir).listFiles().length);
  System.out.println("readdir took " + s);
  System.out.println("num of files " + sb);
  return s.toString();
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Returns a string representation of the current elapsed time; equivalent to
 * {@code toString(4)} (four significant figures).
 */
@GwtIncompatible("String.format()")
@Override public String toString() {
 return toString(4);
}

代码示例来源:origin: org.hudsonci.lib.guava/guava

/**
 * Returns a string representation of the current elapsed time.
 */
@GwtIncompatible("String.format()")
@Override public String toString() {
 return toString(4);
}

代码示例来源:origin: codeine-cd/codeine

private static String createdirs(int files) {
  Stopwatch s = Stopwatch.createStarted();
  for (int i = 0; i < files; i++) {
    FilesUtils.mkdirs(dir + i);
  }
  System.out.println("createdirs took " + s);
  return s.toString();
}

代码示例来源:origin: codeine-cd/codeine

private static String createfiles(int files) {
  Stopwatch s = Stopwatch.createStarted();
  for (int i = 0; i < files; i++) {
    TextFileUtils.setContents(dir + i + "/" + i, "1 " + i);
  }
  System.out.println("createfiles took " + s);
  return s.toString();
}

代码示例来源:origin: codeine-cd/codeine

private static String readfiles(int files) {
  StringBuilder sb = new StringBuilder();
  Stopwatch s = Stopwatch.createStarted();
  for (int i = 0; i < files; i++) {
    sb.append(TextFileUtils.getContents(dir + i + "/" + i));
  }
  System.out.println("readfiles took " + s);
  return s.toString();
}

代码示例来源:origin: codeine-cd/codeine

@SuppressWarnings("unused")
private static String rmdirs(int files) {
  Stopwatch s = Stopwatch.createStarted();
  for (int i = 0; i < files; i++) {
    FilesUtils.delete(dir + i + "/" + i);
    FilesUtils.delete(dir + i);
  }
  System.out.println("rmdirs took " + s);
  return s.toString();
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

private void logImportResult(JournalImportAction action, Stopwatch stopwatch) {
  String msg = String.format("Journals import took %s. Journals: %d (new: %d, modified: %d, unmodified: %d)",
      stopwatch.toString(), action.getTotalCount(), action.getNewJournalsCount(),
      action.getModifiedJournalsCount(), action.getUnmodifiedJournalsCount());
  
  logger.info(msg);
  
  Set<String> missingPbnIds = action.getMissingPbnIds();
  
  if (! missingPbnIds.isEmpty()) {
    int count = missingPbnIds.size();
    String ids = StringUtils.join(missingPbnIds, ", ");
    
    logger.warn("{} journals were not re-imported: {}", count, ids);
  }
  
}

代码示例来源:origin: xvik/dropwizard-guicey

/**
 * Value is reported in best suited units (e.g. milliseconds, seconds, minutes etc).
 *
 * @param name statistic name
 * @return human readable (formatted) timer value or 0 (if stat value is not available)
 * @throws IllegalStateException if provided stat is not time stat
 */
public String humanTime(final Stat name) {
  name.requiresTimer();
  Preconditions.checkState(name.isTimer(), "Stat %s is not timer stat", name);
  final Stopwatch stopwatch = tracker.getTimers().get(name);
  return stopwatch == null ? "0" : stopwatch.toString();
}

代码示例来源:origin: uk.ac.open.kmi.iserve/iserve-semantic-discovery

private synchronized void populate() {
  log.info("Populating Matcher Index...");// if index is empty
  Stopwatch w = new Stopwatch().start();
  Set<URI> classes = new HashSet<URI>(this.manager.getKnowledgeBaseManager().listConcepts(null));
  Map<URI, Map<URI, MatchResult>> matchesTable = sparqlMatcher.listMatchesAtLeastOfType(classes, LogicConceptMatchType.Subsume).rowMap();
  for (URI c : classes) {
    if (matchesTable.get(c) != null) {
      indexedMatches.put(c, new ConcurrentHashMap(matchesTable.get(c)));
    }
  }
  log.info("Population done in {}. Number of entries {}", w.stop().toString(), indexedMatches.size());
}

代码示例来源:origin: restx/restx

@Override
  public void cleanUp() {
    try {
      localMachines.removeMachine(customizerMachine);
      MongoClientURI mongoClientURI = new MongoClientURI(
          checkNotNull(params.get(DB_URI),
              DB_URI + " param is required"));
      Jongo jongo = new Jongo(new MongoClient(mongoClientURI).getDB(mongoClientURI.getDatabase()));
      Stopwatch stopwatch = Stopwatch.createStarted();
      jongo.getCollection(given.getCollection()).drop();
      System.out.printf("dropped %s -- %s%n", given.getCollection(), stopwatch.stop().toString());
    } catch (UnknownHostException e) {
      throw new RuntimeException(e);
    }
  }
};

代码示例来源:origin: org.locationtech.geogig/geogig-core

private void benchmarkIteration(Iterator<RevCommit> commits) {
  NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
  Stopwatch sw = Stopwatch.createStarted();
  sw.reset().start();
  int c = 0;
  while (commits.hasNext()) {
    c++;
    commits.next();
  }
  sw.stop();
  System.err.println("Iterated " + numberFormat.format(c) + " commits in " + sw.toString());
}

代码示例来源:origin: locationtech/geogig

private void benchmarkIteration(Iterator<RevCommit> commits) {
  NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
  Stopwatch sw = Stopwatch.createStarted();
  sw.reset().start();
  int c = 0;
  while (commits.hasNext()) {
    c++;
    commits.next();
  }
  sw.stop();
  System.err.println("Iterated " + numberFormat.format(c) + " commits in " + sw.toString());
}

代码示例来源:origin: org.geogit/geogit-core

private void benchmarkIteration(Iterator<RevCommit> commits) {
  NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
  Stopwatch sw = new Stopwatch();
  sw.reset().start();
  int c = 0;
  while (commits.hasNext()) {
    c++;
    commits.next();
  }
  sw.stop();
  System.err.println("Iterated " + numberFormat.format(c) + " commits in " + sw.toString());
}

代码示例来源:origin: codeine-cd/codeine

private void sendNotificationIfNeeded() {
  if (new NotificationChecker()
    .shouldSendNotification(snoozeKeeper, collectorInfo, project.name(), node.name(), notificationsCount,
      result, previousResult)) {
    notificationDeliverToDatabase
      .sendCollectorResult(collectorInfo.name(), node, project, result.output(), result.exit(),
        stopwatch.toString(), true, (int) notificationsCount.size());
  }
  previousResult = result;
}

相关文章