Table of Contents

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

string

Properties

ElapsedMilliseconds

Gets the total elapsed time in milliseconds.

public long ElapsedMilliseconds { get; }

Property Value

long

ElapsedStringBuilder

Accumulates elapsed time messages from multiple operations.

public StringBuilder ElapsedStringBuilder { get; set; }

Property Value

StringBuilder

LastMessage

Stores the last message generated by a stop-and-print operation.

public string? LastMessage { get; set; }

Property Value

string

Stopwatch

Underlying stopwatch used for time measurement.

public Stopwatch Stopwatch { get; set; }

Property Value

Stopwatch

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

operationName string

Name 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

operationName string

Name 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

operationName string

Name of the operation being measured.

formatSuffix string

Additional format string appended after the elapsed time.

formatArguments string[]

Arguments for the format string.

Returns

long

Elapsed time in milliseconds.