Class StopWatch

java.lang.Object
net.imglib2.util.StopWatch

public class StopWatch extends Object
Utility class to measure time differences in nano-seconds, based on System.nanoTime(). It compensates glitches in System.nanoTime(), such that the stop time can never be earlier than the start time. (For example, see stackoverflow)
  • Field Details

    • time

      private long time
    • total

      private long total
    • started

      private long started
    • running

      private boolean running
    • format

      private static DecimalFormat format
  • Constructor Details

    • StopWatch

      private StopWatch()
      Use createStopped() or createAndStart() to create a StopWatch. This constructor will also create a StopWatch, just like createStopped(), but the more expressively named factory methods are preferred.
  • Method Details

    • createStopped

      public static StopWatch createStopped()
      Construct new StopWatch. It is not running initially. Call start() to start timing.
    • createAndStart

      public static StopWatch createAndStart()
      Construct and start a new StopWatch.
    • safeNanos

      private long safeNanos()
    • start

      public void start()
      Start the clock.
    • stop

      public void stop()
      Stop the clock.
    • nanoTime

      public long nanoTime()
      Get the total time the clock was running, in nano-seconds. Note that the clock can be started and stopped multiple times, accumulating the time intervals it was running in between.
      Returns:
      the total time the clock was running, in nano-seconds.
    • seconds

      public double seconds()
      Get the total time the clock was running in seconds. Note that the clock can be started and stopped multiple times, accumulating the time intervals it was running in between.
    • toString

      public String toString()
      Get the total time the clock was running as string. Note that the clock can be started and stopped multiple times, accumulating the time intervals it was running in between.
      Overrides:
      toString in class Object
    • secondsToString

      public static String secondsToString(double seconds)