gpt4 book ai didi

java - Guava Stopwatch类有什么优势?

转载 作者:行者123 更新时间:2023-12-04 11:37:42 26 4
gpt4 key购买 nike

在 Google Guava 库中,有一个 Stopwatch 类,它的 documentation说明这一点 -

An object that measures elapsed time in nanoseconds. It is useful to measure elapsed time using this class instead of direct calls to System.nanoTime() for a few reasons:

  1. An alternate time source can be substituted, for testing or performance reasons.
  2. As documented by nanoTime, the value returned has no absolute meaning, and can only be interpreted as relative to another timestamp returned by nanoTime at a different time. Stopwatch is a more effective abstraction because it exposes only these relative values, not the absolute ones.

问题 - 他们指的这个“备用时间源”是什么? JRE/JVM 是否也提供此选项?

最佳答案

请参阅 Stopwatch(Ticker) 构造函数。提供您自己的 Ticker 允许您制作一个秒表,该秒表会产生用于测试目的的可预测结果。

关于java - Guava Stopwatch类有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15512552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com