Class EnumerableMeasurement
Extension methods for measuring exact evaluation time of lazy
Namespace: Libplanet
Assembly: Libplanet.dll
Syntax
public static class EnumerableMeasurement : object
Methods
| Improve this Doc View SourceOnBeforeAndAfter<T>(IEnumerable<T>, System.Action, System.Action)
Invokes the specified actions before and after the actual evaluation of the specified
enumerable
object.
Declaration
public static IEnumerable<T> OnBeforeAndAfter<T>(this IEnumerable<T> enumerable, System.Action before, System.Action after)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | An enumerable object. |
System.Action | before | An action to be invoked right before enumeration. |
System.Action | after | An action to be invoked right after enumeration. |
Returns
Type | Description |
---|---|
IEnumerable<T> | Equivalent to |
Type Parameters
Name | Description |
---|---|
T | The type of the elements of |
Examples
Console.WriteLine("Before GetStream() call."); IEnumerable<int> stream = GetStream().OnBeforeAndAfter( before: () => Console.WriteLine("Before enumeration."), after: () => Console.WriteLine("After enumeration.") ); Console.WriteLine("After GetStream() call."); foreach (int i in stream) Console.WriteLine("Enumerating... {0}", i); // Output: // Before GetStream() call. // After GetStream() call. // Before enumeration. // Enumerating... 1 // Enumerating... 2 // ... // After enumeration.
| Improve this Doc View SourceWithMeasuringTime<T>(IEnumerable<T>, System.Action<Stopwatch>)
Measures how long it takes to actually evaluate the specified
enumerable
and then reports the elapsed time through
the specified onMeasured
callback.
Declaration
public static IEnumerable<T> WithMeasuringTime<T>(this IEnumerable<T> enumerable, System.Action<Stopwatch> onMeasured)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | An enumerable object. |
System.Action<Stopwatch> | onMeasured | A callback to be invoked when the enumeration and its
measurement is done. A |
Returns
Type | Description |
---|---|
IEnumerable<T> | Equivalent to |
Type Parameters
Name | Description |
---|---|
T | The type of the elements of |
Examples
IEnumerable<int> stream = GetStream().WithMeasuringTime( elapsed => Console.WriteLine("Elapsed time: {0} ms", elapsed.ElapsedMilliseconds) ); foreach (int i in stream) Console.WriteLine("Enumerating... {0}", i); // Output: // Enumerating... 1 // Enumerating... 2 // ... // Elapsed time: ... ms