Class Stopwatch

java.lang.Object
nl.colorize.util.Stopwatch

public class Stopwatch extends Object
A timer with millisecond precision. Although the timer granularity is in milliseconds, the timer resolution is dependent on the platform and might be more than 1 millisecond. Depending on the platform, either System.currentTimeMillis() or System.nanoTime() will be used for the underlying timer.

This class is not thread safe, Stopwatch instances should not be shared between multiple threads.

  • Constructor Details

    • Stopwatch

      public Stopwatch()
  • Method Details

    • value

      public long value()
      Returns the current value of the underlying timer. Although the absolute value is meaningless, multiple invocations of this method can be compared against each other to determine the elapsed time.
    • tick

      public long tick()
      Marks this point in time. Calling tock() will return the time relative to this point. Returns the interval between now and the previous tick, in milliseconds.
    • tock

      public long tock()
      Returns the time since the last tick(), but does not set a new tick. Returns the interval between now and the previous tick, in milliseconds.