Class Measure

java.lang.Object
de.galan.commons.util.Measure

public class Measure extends Object
Measures invocation of Runnables/Callables in milliseconds. Average of n-invocations can also be calculated (using the '.every(n)' builder method). A total can be logged using finish() on the Measure object. Thread-safe.
  • Method Details

    • measure

      public static Measure measure(String what)
      Builds a new Measure object to measure invocations of runnables/callables.
    • every

      public Measure every(Integer iterations)
      If provided, the average on a single invocation will be calculated/logged after every n-iterations.
    • logStartMessage

      public Measure logStartMessage(boolean logStartMessage)
    • finish

      public Double finish()
      This method can be called to print the total amount of time taken until that point in time.
    • runnable

      public Measure runnable(Runnable runnable)
      Measure the invocation time of the given Runnable (without Exception).
    • run

      public Measure run(ExceptionalRunnable runnable) throws Exception
      Measure the invocation time of the given ExceptionalRunnable.
      Throws:
      Exception
    • call

      public <V> V call(Callable<V> callable) throws Exception
      Measure the invocation time of the given Callable.
      Throws:
      Exception