Class StopWatch

    • Constructor Detail

      • StopWatch

        protected StopWatch​(boolean bStart)
        Constructor.
        Parameters:
        bStart - if true the stop watch is directly started!
    • Method Detail

      • reset

        @Nonnull
        public EChange reset()
        Reset all saved durations, in case this stop watch is to be used in a loop. Does not change the start/stop state.
        Returns:
        EChange.
      • getCurrentNanoTime

        protected static final long getCurrentNanoTime()
        Returns:
        The current time in nano seconds.
      • restart

        public void restart()
        Stops, resets and starts the stop watch.
        See Also:
        stop(), reset(), start()
      • isStarted

        public boolean isStarted()
        Returns:
        true if the stop watch is currently started (running), false otherwise.
      • isStopped

        public boolean isStopped()
        Returns:
        true if the stop watch is currently stopped (not running), false otherwise.
      • getNanos

        @Nonnegative
        public long getNanos()
        Returns:
        The elapsed nano seconds (1000 nano seconds = 1 milli second).
      • getMillis

        @Nonnegative
        public long getMillis()
        Returns:
        The elapsed milli seconds.
      • getDuration

        @Nonnull
        public Duration getDuration()
        Returns:
        The elapsed duration. Never null.
      • stopAndGetMillis

        @Nonnegative
        public long stopAndGetMillis()
        Stop the stop watch and get the elapsed milliseconds since the start. If the stop watch was started and stopped multiple times, the duration is added.
        Returns:
        The elapsed milli seconds or 0 if the stop watch was never started.
      • stopAndGetDuration

        @Nonnull
        public Duration stopAndGetDuration()
        Stop the stop watch and get the duration since the start. If the stop watch was started and stopped multiple times, the duration is added.
        Returns:
        The elapsed duration or 0 if the stop watch was never started.
      • getLapDuration

        @Nonnull
        public Duration getLapDuration()
        Create an intermediate time (lap time). It internally stops, takes the duration and restarts.
        Returns:
        The elapsed duration or 0 if the stop watch was never started.
        Since:
        10.0.0
      • runMeasured

        @Nonnull
        public static Duration runMeasured​(@Nonnull
                                           Runnable aRunnable)
        Run the passed runnable and measure the time. In v10 this was changed to return Duration instead of TimeValue.
        Parameters:
        aRunnable - The runnable to be executed. May not be null.
        Returns:
        The elapsed Duration. Never null.