Home | History | Annotate | Download | only in base

Lines Matching defs:Stopwatch

45  *     returned by {@code nanoTime} at a different time. {@code Stopwatch} is a
52 * Stopwatch stopwatch = Stopwatch.{@link #createStarted createStarted}();
54 * stopwatch.{@link #stop stop}(); // optional
56 * long millis = stopwatch.elapsed(MILLISECONDS);
58 * log.info("time: " + stopwatch); // formatted string like "12.3 ms"</pre>
60 * <p>Stopwatch methods are not idempotent; it is an error to start or stop a
61 * stopwatch that is already in the desired state.
67 * simulate any valid behavior of the stopwatch.
76 public final class Stopwatch {
83 * Creates (but does not start) a new stopwatch using {@link System#nanoTime}
88 public static Stopwatch createUnstarted() {
89 return new Stopwatch();
93 * Creates (but does not start) a new stopwatch, using the specified time
98 public static Stopwatch createUnstarted(Ticker ticker) {
99 return new Stopwatch(ticker);
103 * Creates (and starts) a new stopwatch using {@link System#nanoTime}
108 public static Stopwatch createStarted() {
109 return new Stopwatch().start();
113 * Creates (and starts) a new stopwatch, using the specified time
118 public static Stopwatch createStarted(Ticker ticker) {
119 return new Stopwatch(ticker).start();
123 * Creates (but does not start) a new stopwatch using {@link System#nanoTime}
126 * @deprecated Use {@link Stopwatch#createUnstarted()} instead.
129 Stopwatch() {
134 * Creates (but does not start) a new stopwatch, using the specified time
137 * @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead.
140 Stopwatch(Ticker ticker) {
145 * Returns {@code true} if {@link #start()} has been called on this stopwatch,
154 * Starts the stopwatch.
156 * @return this {@code Stopwatch} instance
157 * @throws IllegalStateException if the stopwatch is already running.
159 public Stopwatch start() {
160 checkState(!isRunning, "This stopwatch is already running.");
167 * Stops the stopwatch. Future reads will return the fixed duration that had
170 * @return this {@code Stopwatch} instance
171 * @throws IllegalStateException if the stopwatch is already stopped.
173 public Stopwatch stop() {
175 checkState(isRunning, "This stopwatch is already stopped.");
182 * Sets the elapsed time for this stopwatch to zero,
185 * @return this {@code Stopwatch} instance
187 public Stopwatch reset() {
198 * Returns the current elapsed time shown on this stopwatch, expressed