Package ucb.util

Class Stopwatch

java.lang.Object
ucb.util.Stopwatch

public class Stopwatch extends Object
A simple timer class based on elapsed wall-clock time. May be stopped and started under program control, and provides both accumulated time and time since last started in units of msec. At any given point, a given timer has some number of properly nested subtimers running. While one subtimer is running, you can start and stop another, allowing you to time parts of some larger activity while still computing the time for the entire activity.
  • Constructor Summary

    Constructors
    Constructor
    Description
    A stopped timer(! isRunning()) with 0msec accumulated time.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Return the total time in milliseconds that isRunning() has been true since THIS was created or reset.
    long
    Return the time in milliseconds since the latest, still-running subtimer started.
    int
    Return the number of nested subtimers currently running.
    boolean
    Return true iff there are subtimers of THIS running.
    void
    Stop all subtimers, and set accumulated time to 0.
    void
    Start a new subtimer at the current time.
    long
    Stops the most recently started, still-running subtimer, returning the time elapsed since it started in milliseconds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Stopwatch

      public Stopwatch()
      A stopped timer(! isRunning()) with 0msec accumulated time.
  • Method Details

    • isRunning

      public boolean isRunning()
      Return true iff there are subtimers of THIS running.
    • getRunning

      public int getRunning()
      Return the number of nested subtimers currently running.
    • start

      public void start()
      Start a new subtimer at the current time.
    • stop

      public long stop()
      Stops the most recently started, still-running subtimer, returning the time elapsed since it started in milliseconds. Throws IllegalStateException if !isRunning().
    • getElapsed

      public long getElapsed()
      Return the time in milliseconds since the latest, still-running subtimer started. Throws IllegalStateException if !isRunning().
    • getAccum

      public long getAccum()
      Return the total time in milliseconds that isRunning() has been true since THIS was created or reset.
    • reset

      public void reset()
      Stop all subtimers, and set accumulated time to 0.