Table of Contents

Class StopwatchStatic

Namespace
SunamoStopwatch
Assembly
SunamoStopwatch.dll

Provides static stopwatch functionality for measuring elapsed time of operations.

public static class StopwatchStatic
Inheritance
StopwatchStatic
Inherited Members

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 static long ElapsedMilliseconds { get; }

Property Value

long

ElapsedStringBuilder

Accumulates elapsed time messages from multiple operations.

public static StringBuilder ElapsedStringBuilder { get; set; }

Property Value

StringBuilder

LastMessage

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

public static string? LastMessage { get; }

Property Value

string

Methods

CalculateAverageOfTakes(List<string>, Func<List<int>, string>)

Calculates the average elapsed time for each unique operation from a list of timing records.

public static string CalculateAverageOfTakes(List<string> list, Func<List<int>, string> averageCalculator)

Parameters

list List<string>

List of timing records in the format "operationName takes Nms".

averageCalculator Func<List<int>, string>

Function that calculates average from a list of integers and returns a formatted string.

Returns

string

Formatted string with average times per operation.

PrintElapsedAndContinue(string)

Prints elapsed time for the operation and restarts the stopwatch.

public static void PrintElapsedAndContinue(string operationName)

Parameters

operationName string

Name of the operation being measured.

Reset()

Resets the stopwatch to zero.

public static void Reset()

SaveElapsed(string)

Saves the elapsed time for the specified operation and appends it to the elapsed string builder.

public static void SaveElapsed(string operationName)

Parameters

operationName string

Name of the operation being measured.

Start()

Resets and starts the stopwatch.

public static void Start()

StopAndElapsedMilliseconds()

Stops the stopwatch, resets it, and returns the elapsed milliseconds.

public static long StopAndElapsedMilliseconds()

Returns

long

Elapsed time in milliseconds.

StopAndPrintElapsed(string)

Stops the stopwatch, prints the elapsed time, and returns the elapsed milliseconds.

public static 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 static 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.