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

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

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

Stopwatch.start介绍

[英]Starts the stopwatch.
[中]启动秒表。

代码示例

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

/**
 * Creates (and starts) a new stopwatch, using the specified time source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted(Ticker ticker) {
 return new Stopwatch(ticker).start();
}

代码示例来源:origin: apache/kylin

@Override
  public void finish(CuboidResult result) {
    Stopwatch stopwatch = new Stopwatch().start();
    int nRetries = 0;
    while (!outputQueue.offer(result)) {
      nRetries++;
      long sleepTime = stopwatch.elapsedMillis();
      if (sleepTime > 3600000L) {
        stopwatch.stop();
        throw new RuntimeException(
            "OutputQueue Full. Cannot offer to the output queue after waiting for one hour!!! Current queue size: "
                + outputQueue.size());
      }
      logger.warn("OutputQueue Full. Queue size: " + outputQueue.size() + ". Total sleep time : " + sleepTime
          + ", and retry count : " + nRetries);
      try {
        Thread.sleep(5000L);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
    stopwatch.stop();
  }
}

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

@Override
public void run()
{
  //System.out.println("DynamicFutureTask.run");
  try
  {
    m_stopwatch.start();
    super.run();
    m_stopwatch.stop();
    m_ingestTimeStats.addValue(m_stopwatch.elapsed(TimeUnit.MICROSECONDS));
  }
  finally
  {
    m_semaphore.release();
  }
}

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

public void testStop_alreadyStopped() {
 stopwatch.start();
 stopwatch.stop();
 try {
  stopwatch.stop();
  fail();
 } catch (IllegalStateException expected) {
 }
 assertFalse(stopwatch.isRunning());
}

代码示例来源:origin: stackoverflow.com

final int MSG_UPDATE_TIMER = 2;
Stopwatch timer = new Stopwatch();
final int REFRESH_RATE = 100;
    switch (msg.what) {
    case MSG_START_TIMER:
      timer.start(); //start timer
      mHandler.sendEmptyMessage(MSG_UPDATE_TIMER);
      break;
    case MSG_STOP_TIMER:
      timer.stop();//stop timer
      tvTextView.setText(""+ timer.getElapsedTime());
      break;

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

/**
 * Creates (and starts) a new stopwatch using {@link System#nanoTime} as its time source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted() {
 return new Stopwatch().start();
}

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

public void testElapsed_multipleSegments() {
 stopwatch.start();
 ticker.advance(9);
 stopwatch.stop();
 ticker.advance(16);
 stopwatch.start();
 assertEquals(9, stopwatch.elapsed(NANOSECONDS));
 ticker.advance(25);
 assertEquals(34, stopwatch.elapsed(NANOSECONDS));
 stopwatch.stop();
 ticker.advance(36);
 assertEquals(34, stopwatch.elapsed(NANOSECONDS));
}

代码示例来源:origin: apache/kylin

@Test
public void createDirectChildrenCacheStressTest() {
  Stopwatch sw = new Stopwatch();
  sw.start();
  Set<Long> cuboidSet = generateMassCuboidSet();
  System.out.println("Time elapsed for creating sorted cuboid list: " + sw.elapsedMillis());
  sw.reset();
  sw.start();
  checkDirectChildrenCacheStressTest(CuboidStatsUtil.createDirectChildrenCache(cuboidSet));
  System.out.println("Time elapsed for creating direct children cache: " + sw.elapsedMillis());
  sw.stop();
}

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

/**
 * Creates (and starts) a new stopwatch using {@link System#nanoTime} as its time source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted() {
 return new Stopwatch().start();
}

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

@Override
public void finished() {
 policyStats.stopwatch().start();
 while (!future.isEmpty()) {
  process(future.dequeueLong());
 }
 policyStats.stopwatch().stop();
}

代码示例来源:origin: apache/kylin

private void testEnumeratorValues(String file) throws Exception {
  InputStream is = new FileInputStream(file);
  ArrayList<String> str = loadStrings(is);
  TrieDictionaryBuilder<String> b = newDictBuilder(str);
  TrieDictionary<String> dict = b.build(0);
  System.out.println("Dictionary size for file " + file + " is " + dict.getSize());
  Stopwatch sw = new Stopwatch();
  sw.start();
  List<String> values1 = dict.enumeratorValuesByParent();
  System.out.println("By iterating id visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms");
  sw.reset();
  sw.start();
  List<String> values2 = dict.enumeratorValues();
  System.out.println("By pre-order visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms");
  sw.stop();
  assertEquals(Sets.newHashSet(values1), Sets.newHashSet(values2));
}

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

/**
 * Creates (and starts) a new stopwatch, using the specified time source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted(Ticker ticker) {
 return new Stopwatch(ticker).start();
}

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

public void testStop() {
 stopwatch.start();
 assertSame(stopwatch, stopwatch.stop());
 assertFalse(stopwatch.isRunning());
}

代码示例来源:origin: apache/kylin

@Test
  public void testGetLongestDepth() {
    Stopwatch sw = new Stopwatch();

    Set<Long> cuboidSet1 = Sets.newHashSet(7L, 6L, 5L, 4L, 3L, 2L, 1L);
    sw.start();
    assertEquals(2, CuboidUtil.getLongestDepth(cuboidSet1));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    Set<Long> cuboidSet2 = Sets.newHashSet(1024L, 1666L, 1667L, 1728L, 1730L, 1731L, 1760L, 1762L, 1763L, 1776L,
        1778L, 1779L, 1784L, 1788L, 1790L, 1791L, 1920L, 1922L, 1923L, 1984L, 1986L, 1987L, 2016L, 2018L, 2019L,
        2032L, 2034L, 2035L, 2040L, 2044L, 2046L, 2047L);
    sw.reset();
    sw.start();
    assertEquals(8, CuboidUtil.getLongestDepth(cuboidSet2));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    Set<Long> cuboidSet3 = Sets.newHashSet(31L, 11L, 5L, 3L, 1L);
    sw.reset();
    sw.start();
    assertEquals(3, CuboidUtil.getLongestDepth(cuboidSet3));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    sw.stop();
  }
}

代码示例来源:origin: thinkaurelius/titan

/**
 * Creates (and starts) a new stopwatch, using the specified time
 * source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted(Ticker ticker) {
  return new Stopwatch(ticker).start();
}

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

public void testElapsed_notRunning() {
 ticker.advance(1);
 stopwatch.start();
 ticker.advance(4);
 stopwatch.stop();
 ticker.advance(9);
 assertEquals(4, stopwatch.elapsed(NANOSECONDS));
}

代码示例来源:origin: apache/kylin

CuboidResultWatcher resultWatcher = new CuboidResultWatcher(builderList, output);
Stopwatch sw = new Stopwatch();
sw.start();
logger.info("Dogged Cube Build2 start");
try {
  output.close();
  closeGirdTables(builderList);
  sw.stop();
  builderPool.shutdownNow();
  logger.info("Dogged Cube Build2 end, totally took " + sw.elapsedMillis() + " ms");

代码示例来源:origin: thinkaurelius/titan

/**
 * Creates (and starts) a new stopwatch using {@link System#nanoTime}
 * as its time source.
 *
 * @since 15.0
 */
public static Stopwatch createStarted() {
  return new Stopwatch().start();
}

代码示例来源:origin: apache/hive

/**
 * Poll more records from the Kafka Broker.
 *
 * @throws PollTimeoutException if poll returns 0 record  and consumer's position < requested endOffset.
 */
private void pollRecords() {
 if (LOG.isTraceEnabled()) {
  stopwatch.reset().start();
 }
 records = consumer.poll(pollTimeoutDurationMs);
 if (LOG.isTraceEnabled()) {
  stopwatch.stop();
  LOG.trace("Pulled [{}] records in [{}] ms", records.count(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
 }
 // Fail if we can not poll within one lap of pollTimeoutMs.
 if (records.isEmpty() && consumer.position(topicPartition) < endOffset) {
  throw new PollTimeoutException(String.format(ERROR_POLL_TIMEOUT_FORMAT,
    pollTimeoutMs,
    topicPartition.toString(),
    startOffset,
    consumer.position(topicPartition),
    endOffset));
 }
 consumerRecordIterator = records.iterator();
 consumerPosition = consumer.position(topicPartition);
}

代码示例来源:origin: apache/kylin

protected CuboidResult scanAndAggregateGridTable(GridTable gridTable, GridTable newGridTable, long parentId,
    long cuboidId, ImmutableBitSet aggregationColumns, ImmutableBitSet measureColumns) throws IOException {
  Stopwatch sw = new Stopwatch();
  sw.start();
  logger.info("Calculating cuboid {}", cuboidId);
    builder.close();
  sw.stop();
  logger.info("Cuboid {} has {} rows, build takes {}ms", cuboidId, count, sw.elapsedMillis());

相关文章