Show / Hide Table of Contents

Class EnumerableMeasurement

Extension methods for measuring exact evaluation time of lazy IEnumerable<T> objects.

Inheritance
Object
EnumerableMeasurement
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet
Assembly: Libplanet.dll
Syntax
public static class EnumerableMeasurement

Methods

| Improve this Doc View Source

OnBeforeAndAfter<T>(IEnumerable<T>, Action, 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, Action before, Action after)
Parameters
Type Name Description
IEnumerable<T> enumerable

An enumerable object.

Action before

An action to be invoked right before enumeration.

Action after

An action to be invoked right after enumeration.

Returns
Type Description
IEnumerable<T>

Equivalent to enumerable.

Type Parameters
Name Description
T

The type of the elements of enumerable.

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 Source

WithMeasuringTime<T>(IEnumerable<T>, 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, Action<Stopwatch> onMeasured)
Parameters
Type Name Description
IEnumerable<T> enumerable

An enumerable object.

Action<Stopwatch> onMeasured

A callback to be invoked when the enumeration and its measurement is done. A Stopwatch instance is passed as the first argument to the callback.

Returns
Type Description
IEnumerable<T>

Equivalent to enumerable.

Type Parameters
Name Description
T

The type of the elements of enumerable.

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

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium