Class TPS


  • public class TPS
    extends java.lang.Object
    This class assists in calculating how many times something happens on a second or to calculate the mean time between calls.
    Please note that this class was designed to be used for debugging or counting small things, when the action is executed more than 1e15 times the error in the total average tps() is very big. Also, this class uses System.nanoTime() so if the elapsed time between the calls to action() is very big, it might yield wrong results
    • Constructor Summary

      Constructors 
      Constructor Description
      TPS()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void action()
      This method is the one that tells the TPS instance that an action has been performed.
      double avgMicros()
      Retrieves the average time in µs between calls to action()
      double avgMilis()
      Retrieves the average time in ms between calls to action()
      double avgNanos()
      Retrieves the average time in ns between calls to action()
      double cAvgMicros()
      Retrieves the average time in µs between calls to action(), considering only the last 50 calls
      double cAvgMilis()
      Retrieves the average time in ms between calls to action(), considering only the last 50 calls
      long cAvgNanos()
      Retrieves the average time in ns between calls to action(), considering only the last 50 calls
      double ctps()
      Retrieves the number of times per second that the action method has been called, considering ONLY the last 50 times
      void reset()
      Resets the current object to it's original state
      java.lang.String toString()  
      double tps()
      Retrieves the number of times per second that the action method has been called
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TPS

        public TPS()
    • Method Detail

      • action

        public void action()
        This method is the one that tells the TPS instance that an action has been performed. It should be called every time the action is executed in order for it to compute the times.
      • tps

        public double tps()
        Retrieves the number of times per second that the action method has been called
        Returns:
        times per second
        See Also:
        ctps()
      • ctps

        public double ctps()
        Retrieves the number of times per second that the action method has been called, considering ONLY the last 50 times
        Returns:
        times per second (last 50 times)
        See Also:
        tps()
      • avgMilis

        public double avgMilis()
        Retrieves the average time in ms between calls to action()
        Returns:
        average time in ms
      • avgMicros

        public double avgMicros()
        Retrieves the average time in µs between calls to action()
        Returns:
        average time in µs
      • avgNanos

        public double avgNanos()
        Retrieves the average time in ns between calls to action()
        Returns:
        average time in ns
      • cAvgMilis

        public double cAvgMilis()
        Retrieves the average time in ms between calls to action(), considering only the last 50 calls
        Returns:
        average time in ms
      • cAvgMicros

        public double cAvgMicros()
        Retrieves the average time in µs between calls to action(), considering only the last 50 calls
        Returns:
        average time in µs
      • cAvgNanos

        public long cAvgNanos()
        Retrieves the average time in ns between calls to action(), considering only the last 50 calls
        Returns:
        average time in ns
      • reset

        public void reset()
        Resets the current object to it's original state
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object