Package org.iam.utils

Class TimeMeasure

java.lang.Object
org.iam.utils.TimeMeasure

public class TimeMeasure extends Object
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 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

      public void stopMeasurement(String operationName)
      Stops measuring time for a specific operation and records the elapsed time.
      Parameters:
      operationName - The name or meaning of the operation.
    • getTimeRecords

      public Map<String,Double> 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

      public static void writeKeysToFile(String filePath, TimeMeasure timeMeasure) throws IOException
      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

      public static void appendValuesToFile(String filePath, TimeMeasure timeMeasure) throws IOException
      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.