Class XTimer


  • public class XTimer
    extends java.lang.Object
    This class implements a simple timer that can be used to quickly profile the speed of operations within library components. The timer simply uses the system time for timing, and thus does not incur significant overhead on runtime.
    Author:
    Christian W. Guenther (christian@deckfour.org)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long DAY_MILLIS
      Milliseconds in one day.
      static long HOUR_MILLIS
      Milliseconds in one hour.
      static long MINUTE_MILLIS
      Milliseconds in one minute.
      static long SECOND_MILLIS
      Milliseconds in one second.
      protected long start
      Start time of timer.
      protected long stop
      Stop time of timer.
    • Constructor Summary

      Constructors 
      Constructor Description
      XTimer()
      Creates a new timer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatDuration​(long millis)
      Formats a duration in milliseconds as a pretty-print string.
      long getDuration()
      Retrieve the runtime of the timer.
      java.lang.String getDurationString()
      Retrieve the runtime of the timer as a pretty-print string.
      void start()
      Starts the timer.
      void stop()
      Stops the timer (takes time).
      • Methods inherited from class java.lang.Object

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

      • DAY_MILLIS

        public static final long DAY_MILLIS
        Milliseconds in one day.
        See Also:
        Constant Field Values
      • HOUR_MILLIS

        public static final long HOUR_MILLIS
        Milliseconds in one hour.
        See Also:
        Constant Field Values
      • MINUTE_MILLIS

        public static final long MINUTE_MILLIS
        Milliseconds in one minute.
        See Also:
        Constant Field Values
      • SECOND_MILLIS

        public static final long SECOND_MILLIS
        Milliseconds in one second.
        See Also:
        Constant Field Values
      • start

        protected long start
        Start time of timer.
      • stop

        protected long stop
        Stop time of timer.
    • Constructor Detail

      • XTimer

        public XTimer()
        Creates a new timer. (starts running implicitly)
    • Method Detail

      • start

        public void start()
        Starts the timer.
      • stop

        public void stop()
        Stops the timer (takes time).
      • getDuration

        public long getDuration()
        Retrieve the runtime of the timer.
        Returns:
        Runtime between start (or creation of timer) and stop, in milliseconds.
      • getDurationString

        public java.lang.String getDurationString()
        Retrieve the runtime of the timer as a pretty-print string.
        Returns:
        Runtime between start (or creation of timer) and stop, as a pretty-print string.
      • formatDuration

        public static java.lang.String formatDuration​(long millis)
        Formats a duration in milliseconds as a pretty-print string.
        Parameters:
        millis - Duration in milliseconds.
        Returns:
        Given duration as a pretty-print string.