Module watamebot

Class MethodTimer

java.lang.Object
net.foxgenesis.util.MethodTimer

public final class MethodTimer extends Object
Utility class that check the amount of time it takes to run a method
Author:
Ashley
  • Constructor Details

    • MethodTimer

      public MethodTimer()
  • Method Details

    • run

      public static double run(Runnable r)
      Time how long it takes to execute Runnable r. Time is calculated in nano seconds and returned as milliseconds.
      Parameters:
      r - - Runnable to time
      Returns:
      elapsed time in milliseconds
      See Also:
    • run

      public static double run(Runnable r, int n)
      Time how long it takes to execute Runnable r, n amount of times. Then calculate the average elapsed time taken.
      Parameters:
      r - - Runnable to time
      n - - Amount of times to run
      Returns:
      average elapsed time milliseconds
      See Also:
    • runFormatMS

      public static String runFormatMS(Runnable r)
      Time how long it takes to execute Runnable r. Time is calculated in nano seconds and returned as a formatted string with two decimal places.

      This method is effectively equivalent to

       MethodTimer.runFormatMS(r, 2)
       
      Parameters:
      r - - Runnable to time
      Returns:
      formatted string with two decimal places
      See Also:
    • runFormatMS

      public static String runFormatMS(Runnable r, int decimals)
      Time how long it takes to execute Runnable r. Time is calculated in nano seconds and returned as a formatted string with decimals decimal places.

      This method is effectively equivalent to

       String.format("%." + decimals + "f ms", run(r))
       
      Parameters:
      r - - Runnable to time
      decimals - - Amount of decimal places to format
      Returns:
      formatted string with decimals decimal places
      See Also:
    • runFormatMS

      public static String runFormatMS(Runnable r, int n, int decimals)
      Time the average elapsed time it takes to execute Runnable r, n amount of times. Time is calculated in nano seconds and returned as a formatted string with decimals decimal places.

      This method is effectively equivalent to

       String.format("%." + decimals + "f ms", run(r, n));
       
      Parameters:
      r - - Runnable to time
      n - - Amount of times to execute r
      decimals - - Amount of decimal places to format
      Returns:
      formatted string with decimals decimal places
      See Also: