org.modeshape.common.statistic

## Class Stopwatch

- java.lang.Object
- - org.modeshape.common.statistic.Stopwatch

- All Implemented Interfaces:
    Comparable<Stopwatch>

      @NotThreadSafe
      public class Stopwatch
      extends Object
      implements Comparable<Stopwatch>

  Provides a mechanism to measure time in the same way as a physical stopwatch.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Stopwatch()`
    `Stopwatch(boolean detailedStats)`
    `Stopwatch(boolean detailedStats, String description)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(Stopwatch that)`
    `Duration` | `getAverageDuration()` Get the average duration that this stopwatch has recorded.
    `int` | `getCount()` Return the number of runs (complete starts and stops) this stopwatch has undergone.
    `String` | `getDescription()`
    `DetailedStatistics<Duration>` | `getDetailedStatistics()` Return this stopwatch's detailed statistics, if they are being kept.
    `Histogram<Duration>` | `getHistogram(int numSigmas)` Return the histogram of this stopwatch's individual runs.
    `Duration` | `getMaximumDuration()` Get the maximum duration that this stopwatch has recorded.
    `Duration` | `getMedianDuration()` Get the median duration that this stopwatch has recorded.
    `Duration` | `getMinimumDuration()` Get the minimum duration that this stopwatch has recorded.
    `SimpleStatistics<Duration>` | `getSimpleStatistics()` Return this stopwatch's simple statistics.
    `Duration` | `getTotalDuration()` Get the total duration that this stopwatch has recorded.
    `boolean` | `isDetailedStatistics()` Return true if detailed statistics are being kept.
    `boolean` | `isRunning()` Return whether this stopwatch is currently running.
    `void` | `lap()` Record the statistics for the latest run, but keep the stopwatch going.
    `void` | `reset()` Reset this stopwatch and clear all statistics.
    `void` | `start()` Start the stopwatch and begin recording the statistics a new run.
    `void` | `stop()` Stop the stopwatch and record the statistics for the latest run.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Stopwatch

          public Stopwatch()

    - #### Stopwatch

          public Stopwatch(boolean detailedStats)

    - #### Stopwatch

          public Stopwatch(boolean detailedStats,
                   String description)

  - ### Method Detail

    - #### getDescription

          public String getDescription()

    - #### start

          public void start()

      Start the stopwatch and begin recording the statistics a new run. This method does nothing if the stopwatch is already `running`
      See Also:
        `isRunning()`

    - #### stop

          public void stop()

      Stop the stopwatch and record the statistics for the latest run. This method does nothing if the stopwatch is not currently `running`
      See Also:
        `isRunning()`

    - #### lap

          public void lap()

      Record the statistics for the latest run, but keep the stopwatch going. This method does nothing if the stopwatch is not currently `running`
      See Also:
        `isRunning()`

    - #### getCount

          public int getCount()

      Return the number of runs (complete starts and stops) this stopwatch has undergone.
      Returns:
        the number of runs.
      See Also:
        `isRunning()`

    - #### isRunning

          public boolean isRunning()

      Return whether this stopwatch is currently running.
      Returns:
        true if running, or false if not

    - #### getTotalDuration

          public Duration getTotalDuration()

      Get the total duration that this stopwatch has recorded.
      Returns:
        the total duration, or an empty duration if this stopwatch has not been used since creation or being `reset`

    - #### getAverageDuration

          public Duration getAverageDuration()

      Get the average duration that this stopwatch has recorded.
      Returns:
        the average duration, or an empty duration if this stopwatch has not been used since creation or being `reset`

    - #### getMedianDuration

          public Duration getMedianDuration()

      Get the median duration that this stopwatch has recorded.
      Returns:
        the median duration, or an empty duration if this stopwatch has not been used since creation or being `reset`

    - #### getMinimumDuration

          public Duration getMinimumDuration()

      Get the minimum duration that this stopwatch has recorded.
      Returns:
        the total minimum, or an empty duration if this stopwatch has not been used since creation or being `reset`

    - #### getMaximumDuration

          public Duration getMaximumDuration()

      Get the maximum duration that this stopwatch has recorded.
      Returns:
        the maximum duration, or an empty duration if this stopwatch has not been used since creation or being `reset`

    - #### getSimpleStatistics

          public SimpleStatistics<Duration> getSimpleStatistics()

      Return this stopwatch's simple statistics.
      Returns:
        the statistics
      See Also:
        `getDetailedStatistics()`

    - #### getDetailedStatistics

          public DetailedStatistics<Duration> getDetailedStatistics()

      Return this stopwatch's detailed statistics, if they are being kept.
      Returns:
        the statistics
      See Also:
        `getSimpleStatistics()`

    - #### isDetailedStatistics

          public boolean isDetailedStatistics()

      Return true if detailed statistics are being kept.
      Returns:
        true if `detailed statistics` are being kept, or false if only `simple statistics` are being kept.

    - #### getHistogram

          public Histogram<Duration> getHistogram(int numSigmas)

      Return the histogram of this stopwatch's individual runs. Two different kinds of histograms can be created. The first kind is a histogram where all of the buckets are distributed normally and all have the same width. In this case, the 'numSigmas' should be set to 0.

      Note: if only `simple statistics` are being kept, the resulting histogram is always empty.

      The second kind of histogram is more useful when most of the data that is clustered near one value. This histogram is focused around the values that are up to 'numSigmas' above and below the `median`, and all values outside of this range are placed in the first and last bucket.

      Parameters:
        `numSigmas` - the number of standard deviations from the `median`, or 0 if the buckets of the histogram should be evenly distributed
      Returns:
        the histogram

    - #### reset

          public void reset()

      Reset this stopwatch and clear all statistics.

    - #### compareTo

          public int compareTo(Stopwatch that)

      Specified by:
        `compareTo` in interface `Comparable<Stopwatch>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.