Class Benchmarker

java.lang.Object
hlcd.operations.Benchmarker

public class Benchmarker extends Object
Used to time the execution duration of a run.
 //minimal example to execute this class:
 public static void main(String[] args) {
     System.out.println("Running Benchmarker...");
     Benchmarker b = new Benchmarker();
     b.start();
     b.displayStartTime("The program started: ");
     try {//dummy timelapse
         Thread.sleep(1500);
     } catch (InterruptedException e) {
         e.printStackTrace();
     }
     b.end();
     b.displayEndTime("The program end: ");
     b.displayLapsedTime("The total time is: ");
     System.out.println("Benchmarker completed.");
 }
Since:
1.8
Version:
1.0 (February 17th, 2022)
Author:
Maysara Al Jumaily
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes the object.
    Benchmarker​(long start, long end)
    Assumes the start and end times were already captured.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Plays a beep audio and usually used when an execution is completed.
    void
    Prints the end time on console in a human-readable format.
    void
    Prints the label on specified on screen along with the end time in a human-readable format.
    void
    Prints the time lapsed on console as a human-readable format.
    void
    Prints the label on specified on screen along with the start time in a human-readable format.
    void
    displayTime​(long t, String label)
    Prints the time specified on console with an attached label.
    void
    end()
    Sets the end mark of the execution time.
    static String
    Returns the current time/date formatted in the following style: dd/MM/yyyy hh:mm:ss.SSS a.
    Returns the time lapsed as a human-readable format.
    static String
    getLapsedTime​(long start, long end)
    Returns the time lapsed as a human-readable format of the start and end time specified.
    void
    Prints the time lapsed on console as a human-readable format.
    void
    Sets the start mark of the execution time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Benchmarker

      public Benchmarker()
      Initializes the object.
    • Benchmarker

      public Benchmarker(long start, long end)
      Assumes the start and end times were already captured.
      Parameters:
      start - the start time of the execution
      end - the end time of the execution
  • Method Details

    • start

      public void start()
      Sets the start mark of the execution time.
    • displayStartTime

      public void displayStartTime(String label)
      Prints the label on specified on screen along with the start time in a human-readable format.
      Parameters:
      label - the label to display on screen before displaying the start time.
    • end

      public void end()
      Sets the end mark of the execution time.
    • displayEndTime

      public void displayEndTime()
      Prints the end time on console in a human-readable format.
    • displayEndTime

      public void displayEndTime(String label)
      Prints the label on specified on screen along with the end time in a human-readable format.
      Parameters:
      label - the label to display on screen before displaying the end time.
    • displayTime

      public void displayTime(long t, String label)
      Prints the time specified on console with an attached label.
      Parameters:
      t - the time to display on console
      label - the label that will be attached with the time
    • getLapsedTime

      public String getLapsedTime()
      Returns the time lapsed as a human-readable format.
      Returns:
      the time lapsed as a human-readable format
    • getLapsedTime

      public static String getLapsedTime(long start, long end)
      Returns the time lapsed as a human-readable format of the start and end time specified.
      Parameters:
      start - the start time of the execution
      end - the end time of the execution
      Returns:
      the time lapsed as a human-readable format
    • printLapsedTime

      public void printLapsedTime()
      Prints the time lapsed on console as a human-readable format.
    • displayLapsedTime

      public void displayLapsedTime(String label)
      Prints the time lapsed on console as a human-readable format.
      Parameters:
      label - the label to append before displaying the timelapse
    • getCurrentDateFormatted

      public static String getCurrentDateFormatted()
      Returns the current time/date formatted in the following style: dd/MM/yyyy hh:mm:ss.SSS a. For example, 02/02/2022 06:02:46 PM
      Returns:
      the current time/date formatted appropriately
    • beep

      public static void beep()
      Plays a beep audio and usually used when an execution is completed.