Show / Hide Table of Contents

Class EnumerableMeasurement

Extension methods for measuring exact evaluation time of lazy objects.

Inheritance
Object
EnumerableMeasurement
Namespace: Libplanet
Assembly: Libplanet.dll
Syntax
public static class EnumerableMeasurement : object

Methods

| Improve this Doc View Source

OnBeforeAndAfter<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 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>, 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 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–2022 Planetarium