Class StopWatch

java.lang.Object
org.nineml.coffeegrinder.util.StopWatch

public class StopWatch extends Object
A utility class for managing a "wall clock" timer.

The timer starts when you create the object. Subsequent calls will return information based on the elapsed wall-clock time since the object was created. If stop is called, it will fix the end time.

  • Constructor Details

    • StopWatch

      public StopWatch()
      Create a stopwatch.

      Time begins counting immediately.

  • Method Details

    • stop

      public void stop()
      Stop the watch.

      After calling this method, the time will remain fixed.

    • duration

      public long duration()
      The number of milliseconds that the stopwatch has been running.

      Or, if stop has been called, how long it ran.

      Returns:
      the number of milliseconds
    • perSecond

      public String perSecond(long events)
      Compute events per second.

      Computes events per second for the given number of events. It returns a string of the form %3.1f.

      Parameters:
      events - The number of events
      Returns:
      A formatted string
    • elapsed

      public String elapsed()
      The elapsed time in a human-friendly format.

      This method uses the timer's elapsed time.

      Returns:
      A formatted string
    • elapsed

      public String elapsed(long duration)
      The elapsed time in a human-friendly format.

      Returns the number of days, minutes, hours, and seconds represented by the duration, a number of milliseconds. For example, 103,010,000ms is "1d4h36m50s".

      Parameters:
      duration - the duration in milliseconds
      Returns:
      A formatted string