Package org.iam.utils
Class TimeMeasure
java.lang.Object
org.iam.utils.TimeMeasure
Utility class for measuring and recording multiple time intervals.
It measures time and stores the results in a LinkedHashMap.
The class can write operation names and elapsed times to a file,
differentiating between single-round total time and all-rounds total time.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendValuesToFile(String filePath, TimeMeasure timeMeasure) Appends the values (elapsed times) of the TimeMeasure's time records to a file.doubleGets the total elapsed time of the current round of operations.Gets the map of time records.doubleGets the total elapsed time of all operations across all rounds.voidStarts measuring time for a specific operation.voidstopMeasurement(String operationName) Stops measuring time for a specific operation and records the elapsed time.static voidwriteKeysToFile(String filePath, TimeMeasure timeMeasure) Writes the keys (operation names) of the TimeMeasure's time records to a file, overwriting the existing content.
-
Constructor Details
-
TimeMeasure
public TimeMeasure()Constructs a new TimeMeasure object. Initializes the timeRecords map, totalTime, singleRoundTotalTime, and startTime.
-
-
Method Details
-
startMeasurement
public void startMeasurement()Starts measuring time for a specific operation. Records the current system time as the start time. -
stopMeasurement
Stops measuring time for a specific operation and records the elapsed time.- Parameters:
operationName- The name or meaning of the operation.
-
getTimeRecords
Gets the map of time records.- Returns:
- A LinkedHashMap containing operation names and their corresponding elapsed times in milliseconds.
-
getTotalTime
public double getTotalTime()Gets the total elapsed time of all operations across all rounds.- Returns:
- The total elapsed time in milliseconds, formatted to two decimal places.
-
getSingleRoundTotalTime
public double getSingleRoundTotalTime()Gets the total elapsed time of the current round of operations.- Returns:
- The single-round total elapsed time in milliseconds, formatted to two decimal places.
-
writeKeysToFile
Writes the keys (operation names) of the TimeMeasure's time records to a file, overwriting the existing content.- Parameters:
filePath- The path of the file to write to.timeMeasure- The TimeMeasure instance containing the time records.- Throws:
IOException- If an I/O error occurs while writing to the file.
-
appendValuesToFile
Appends the values (elapsed times) of the TimeMeasure's time records to a file. Also appends the single-round total time and all-rounds total time.- Parameters:
filePath- The path of the file to append to.timeMeasure- The TimeMeasure instance containing the time records.- Throws:
IOException- If an I/O error occurs while writing to the file.
-