Package hlcd.operations
Class Benchmarker
java.lang.Object
hlcd.operations.Benchmarker
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
ConstructorsConstructorDescriptionInitializes the object.Benchmarker(long start, long end)Assumes the start and end times were already captured. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbeep()Plays a beep audio and usually used when an execution is completed.voidPrints the end time on console in a human-readable format.voiddisplayEndTime(String label)Prints the label on specified on screen along with the end time in a human-readable format.voiddisplayLapsedTime(String label)Prints the time lapsed on console as a human-readable format.voiddisplayStartTime(String label)Prints the label on specified on screen along with the start time in a human-readable format.voiddisplayTime(long t, String label)Prints the time specified on console with an attached label.voidend()Sets the end mark of the execution time.static StringReturns 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 StringgetLapsedTime(long start, long end)Returns the time lapsed as a human-readable format of the start and end time specified.voidPrints the time lapsed on console as a human-readable format.voidstart()Sets the start mark of the execution time.
-
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 executionend- the end time of the execution
-
-
Method Details
-
start
public void start()Sets the start mark of the execution time. -
displayStartTime
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
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
Prints the time specified on console with an attached label.- Parameters:
t- the time to display on consolelabel- the label that will be attached with the time
-
getLapsedTime
Returns the time lapsed as a human-readable format.- Returns:
- the time lapsed as a human-readable format
-
getLapsedTime
Returns the time lapsed as a human-readable format of the start and end time specified.- Parameters:
start- the start time of the executionend- 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
Prints the time lapsed on console as a human-readable format.- Parameters:
label- the label to append before displaying the timelapse
-
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.
-