Class StopWatch


  • public class StopWatch
    extends Object
    Stop watch feature that allows you to time operations
    • Constructor Detail

      • StopWatch

        public StopWatch()
        Create a new StopWatch
      • StopWatch

        public StopWatch​(String description)
        Create a new StopWatch
        Parameters:
        description - Description of the timing - typically a description of what is being timed/measured
    • Method Detail

      • start

        public static StopWatch start​(String description)
        Create a new StopWatch
        Parameters:
        description - Description of the timing - typically a description of what is being timed/measured
        Returns:
        the new StopWatch. Call stop() to end the timing
      • stop

        public Timing stop()
        Call this method to end the timing operation
        Returns:
        the Timing result
      • time

        public static Duration time​(Runnable operation)
        Time how long it takes to perform an operation
        Parameters:
        operation - the operation to perform
        Returns:
        the time it took to perform the operation as a Duration
      • time

        public static <R> TimingWithResult<R> time​(Supplier<R> operation)
        Time how long it takes to perform an operation
        Type Parameters:
        R - The return type of the operation
        Parameters:
        operation - the operation to perform
        Returns:
        the timing result (the result together with the time it took to perform the operation as a Duration)