Table of Contents

Class ExecutionTimer

Namespace
Xunit.v3
Assembly
xunit.v3.core.dll

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

action Action

The action to measure.

Returns

TimeSpan

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

asyncAction Func<ValueTask>

The asynchronous action to measure.

Returns

ValueTask<TimeSpan>

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

asyncFunc Func<ValueTask<T>>

The asynchronous function to measure.

Returns

ValueTask<(T Result, TimeSpan Elapsed)>

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

func Func<T>

The function to measure.

Returns

(T Result, TimeSpan Elapsed)

Type Parameters

T