Class Benchmarker
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum representing profiling modes for benchmarking. -
Constructor Summary
ConstructorsConstructorDescriptionBenchmarker(Benchmarker.ProfilingMode profilingMode) Constructor for the Benchmarker class parameterised with a profiling mode. -
Method Summary
Modifier and TypeMethodDescriptionReturns the benchmark metric based on the profiling mode.voidMeasures the memory usage during the sorting process.voidReports an insert operation during the sorting process.voidReports a shift operation during the sorting process.voidReports a swap operation during the sorting process.voidReports a write operation during the sorting process.voidreportWrites(int count) Reports write operations during the sorting process.voidreset()Resets the benchmarker to its initial state.voidInitiates profiling, resetting any prior metric data, based on the selected profiling mode.voidStops the profiling process based on the selected profiling mode.
-
Constructor Details
-
Benchmarker
Constructor for the Benchmarker class parameterised with a profiling mode.- Parameters:
profilingMode- The profiling mode to be used.- Throws:
IllegalArgumentException- If the profiling mode isnull.
-
-
Method Details
-
startProfiling
public void startProfiling()Initiates profiling, resetting any prior metric data, based on the selected profiling mode.Must be followed by
stopProfiling()to complete metric collection.- Throws:
IllegalStateException- If profiling is already active.
-
stopProfiling
public void stopProfiling()Stops the profiling process based on the selected profiling mode.Must follow a
startProfiling()call to collect metrics.- Throws:
IllegalStateException- If profiling is not in progress.
-
measureMemory
public void measureMemory()Measures the memory usage during the sorting process.This method should only be called when memory profiling is active. The scope of this benchmark is limited to heap memory analysis. Stack memory usage is not measured for simplicity.
- Throws:
IllegalStateException- If profiling is not currently active.
-
reportSwap
public void reportSwap()Reports a swap operation during the sorting process.A swap refers to the exchange of two elements in the array being sorted (also known as invertion). This method increases the data write counter by 2.
-
reportShift
public void reportShift()Reports a shift operation during the sorting process.A shift refers to movement of an element to the right within the array. This method increments the data write counter by 1.
-
reportInsert
public void reportInsert()Reports an insert operation during the sorting process.An insert writes a specified value at a specified location within the array. This method increments the data write counter by 1.
-
reportWrite
public void reportWrite()Reports a write operation during the sorting process.This method increments the data write counter by 1.
-
reportWrites
public void reportWrites(int count) Reports write operations during the sorting process.This method increments the data write counter by the specified amount only when profiling is active and the profiling mode is set to
DATA_WRITE_COUNT.- Parameters:
count- The number of write operations performed.- Throws:
IllegalArgumentException- If count is negative.IllegalStateException- If profiling is not currently active.
-
reset
public void reset()Resets the benchmarker to its initial state.- Throws:
IllegalStateException- if profiling is currently active.
-
getMetric
Returns the benchmark metric based on the profiling mode.- Returns:
- The benchmark iteration metric containing the profiling mode and the corresponding metric value.
- Throws:
IllegalStateException- If the profiling is still in progress or the profiling mode is not set (should not happen).
-