Class TPS

java.lang.Object
com.dkt.graphics.utils.TPS

public class TPS extends 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
Author:
Federico Vera <[email protected]>
  • Constructor Summary

    Constructors
    Constructor
    Description
    TPS()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method is the one that tells the TPS instance that an action has been performed.
    double
    Retrieves the average time in µs between calls to action()
    double
    Retrieves the average time in ms between calls to action()
    double
    Retrieves the average time in ns between calls to action()
    double
    Retrieves the average time in µs between calls to action(), considering only the last 50 calls
    double
    Retrieves the average time in ms between calls to action(), considering only the last 50 calls
    long
    Retrieves the average time in ns between calls to action(), considering only the last 50 calls
    double
    Retrieves the number of times per second that the action method has been called, considering ONLY the last 50 times
    void
    Resets the current object to its original state
     
    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 Details

    • TPS

      public TPS()
  • Method Details

    • 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

      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:
    • 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 its original state
    • toString

      public String toString()
      Overrides:
      toString in class Object