語言: CN / TW / HK
* An object that accurately measures <i>elapsed time</i>: the measured duration between two
* successive readings of "now" in the same process.
* <p>In contrast, <i>wall time</i> is a reading of "now" as given by a method like
* { @link System#currentTimeMillis()}, best represented as an { @link Instant}. Such values
* <i>can</i> be subtracted to obtain a { @code Duration} (such as by { @code Duration.between}), but
* doing so does <i>not</i> give a reliable measurement of elapsed time, because wall time readings
* are inherently approximate, routinely affected by periodic clock corrections. Because this class
* (by default) uses { @link System#nanoTime}, it is unaffected by these changes.
*作為對照,實際時間是讀取當前時間,就像System.currentTimeMillis()方法,一瞬間的最好代表。這種值相減可以得到一段時間,但是這樣得不到準確的消耗的時間,因為實際時間讀取是本質上近似的, 經常受到週期性時鐘校正的影響。因為這個類使用System.nanoTime方法,它不受這些變化的影響
* <p>Use this class instead of direct calls to {@link System#nanoTime} for two reasons:
* <ul>
* <li>The raw {@code long} values returned by {@code nanoTime} are meaningless and unsafe to use
* in any other way than how {@code Stopwatch} uses them.
* <li>An alternative source of nanosecond ticks can be substituted, for example for testing or
* performance reasons, without affecting most of your code.
* </ul>
* <p>Basic usage:
* <pre>{@code
* Stopwatch stopwatch = Stopwatch.createStarted();
* doSomething();
* stopwatch.stop(); // optional
* Duration duration = stopwatch.elapsed();
*"time: " + stopwatch); // formatted string like "12.3 ms"
* }</pre>
* <p>The state-changing methods are not idempotent; it is an error to start or stop a stopwatch
* that is already in the desired state.
* <p>When testing code that uses this class, use {@link #createUnstarted(Ticker)} or {@link
* #createStarted(Ticker)} to supply a fake or mock ticker. This allows you to simulate any valid
* behavior of the stopwatch.
* <p><b>Note:</b> This class is not thread-safe.
* <p><b>Warning for Android users:</b> a stopwatch with default behavior may not continue to keep
* time while the device is asleep. Instead, create one like this:
* <pre>{@code
* Stopwatch.createStarted(
* new Ticker() {
* public long read() {
* return android.os.SystemClock.elapsedRealtimeNanos();
* }
* });
* }</pre>
* @author Kevin Bourrillion
* @since 10.0