Class StopwatchHelper
- Namespace
- SunamoStopwatch
- Assembly
- SunamoStopwatch.dll
Provides instance-based stopwatch functionality for measuring elapsed time of operations.
public class StopwatchHelper
- Inheritance
-
StopwatchHelper
- Inherited Members
- Extension Methods
Fields
Takes
Separator text used between operation name and elapsed time.
public const string Takes = " takes "
Field Value
Properties
ElapsedMilliseconds
Gets the total elapsed time in milliseconds.
public long ElapsedMilliseconds { get; }
Property Value
ElapsedStringBuilder
Accumulates elapsed time messages from multiple operations.
public StringBuilder ElapsedStringBuilder { get; set; }
Property Value
LastMessage
Stores the last message generated by a stop-and-print operation.
public string? LastMessage { get; set; }
Property Value
Stopwatch
Underlying stopwatch used for time measurement.
public Stopwatch Stopwatch { get; set; }
Property Value
Methods
Reset()
Resets the stopwatch to zero.
public void Reset()
SaveElapsed(string)
Saves the elapsed time for the specified operation and appends it to the elapsed string builder.
public void SaveElapsed(string operationName)
Parameters
operationNamestringName of the operation being measured.
Start()
Resets and starts the stopwatch.
public void Start()
Stop()
Stops the stopwatch, resets it, and returns the elapsed time as a string.
public string Stop()
Returns
- string
Elapsed time in milliseconds formatted as a string.
StopAndPrintElapsed(string)
Stops the stopwatch, prints the elapsed time, and returns the elapsed milliseconds.
public long StopAndPrintElapsed(string operationName)
Parameters
operationNamestringName of the operation being measured.
Returns
- long
Elapsed time in milliseconds.
StopAndPrintElapsed(string, string, params string[])
Stops the stopwatch, prints the elapsed time with optional format arguments, and returns the elapsed milliseconds.
public long StopAndPrintElapsed(string operationName, string formatSuffix, params string[] formatArguments)
Parameters
operationNamestringName of the operation being measured.
formatSuffixstringAdditional format string appended after the elapsed time.
formatArgumentsstring[]Arguments for the format string.
Returns
- long
Elapsed time in milliseconds.