Class Timer


  • public class Timer
    extends java.lang.Object
    A class for timing calculations to test efficiency
    Author:
    Bhagat
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long startTime  
    • Constructor Summary

      Constructors 
      Constructor Description
      Timer()
      creates a Timer object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long elapsed()  
      void restart()
      calls the start method
      void start()
      starts the timer by initializing the startTime to the current time
      static long time​(Function<java.lang.Void,​java.lang.Void> function)
      times a function
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • startTime

        private long startTime
    • Constructor Detail

      • Timer

        public Timer()
        creates a Timer object
    • Method Detail

      • start

        public void start()
        starts the timer by initializing the startTime to the current time
      • restart

        public void restart()
        calls the start method
      • elapsed

        public long elapsed()
        Returns:
        the time elapsed in milliseconds since the timer started
      • time

        public static long time​(Function<java.lang.Void,​java.lang.Void> function)
        times a function
        Parameters:
        function - the function to time
        Returns:
        the number of milliseconds elapsed