Class ExecutionTimer
The methods on this static class can measure the time taken to execute actions (both synchronous and asynchronous).
public static class ExecutionTimer
- Inheritance
-
ExecutionTimer
- Inherited Members
Methods
Measure(Action)
Executes an action and returns the amount of time it took to execute. Note: time cannot be measured for any action that throws an exception, so this should only be called by code that is known not to throw (f.e., using ExceptionAggregator) or when the execution time for throwing code is irrelevant.
public static TimeSpan Measure(Action action)
Parameters
actionActionThe action to measure.
Returns
MeasureAsync(Func<ValueTask>)
Executes an asynchronous action and returns the amount of time it took to execute. Note: time cannot be measured for any action that throws an exception, so this should only be called by code that is known not to throw (f.e., using ExceptionAggregator) or when the execution time for throwing code is irrelevant.
public static ValueTask<TimeSpan> MeasureAsync(Func<ValueTask> asyncAction)
Parameters
Returns
MeasureAsync<T>(Func<ValueTask<T>>)
Executes an asynchronous function and returns the amount of time it took to execute. Note: time cannot be measured for any action that throws an exception, so this should only be called by code that is known not to throw (f.e., using ExceptionAggregator) or when the execution time for throwing code is irrelevant.
public static ValueTask<(T Result, TimeSpan Elapsed)> MeasureAsync<T>(Func<ValueTask<T>> asyncFunc)
Parameters
Returns
Type Parameters
T
Measure<T>(Func<T>)
Executes a function and returns the amount of time it took to execute. Note: time cannot be measured for any action that throws an exception, so this should only be called by code that is known not to throw (f.e., using ExceptionAggregator) or when the execution time for throwing code is irrelevant.
public static (T Result, TimeSpan Elapsed) Measure<T>(Func<T> func)
Parameters
funcFunc<T>The function to measure.
Returns
Type Parameters
T