Class ParamWrapper<T>
A generic wrapper to associate strongly typed parameter or argument values with a display text.
Implements
Namespace: Mawosoft.Extensions.BenchmarkDotNet
Assembly: Mawosoft.Extensions.BenchmarkDotNet.dll
Syntax
public class ParamWrapper<T> : Object
Type Parameters
Name | Description |
---|---|
T | The type of the wrapped value. |
Examples
public IEnumerable<MemoryStream> ArgumentsSource_NotWrapped()
{
yield return new MemoryStream(50);
yield return new MemoryStream(500);
}
public IEnumerable<ParamWrapper<MemoryStream>> ArgumentsSource_Wrapped()
{
yield return new ParamWrapper<MemoryStream>(new MemoryStream(50), "small stream");
yield return new ParamWrapper<MemoryStream>(new MemoryStream(500), "big stream");
}
[Benchmark]
[ArgumentsSource(nameof(ArgumentsSource_NotWrapped))]
public void NotWrapped(MemoryStream input)
{
input.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[10];
while (input.Read(buffer, 0, buffer.Length) == buffer.Length) { }
}
[Benchmark]
[ArgumentsSource(nameof(ArgumentsSource_Wrapped))]
public void Wrapped(ParamWrapper<MemoryStream> input)
{
MemoryStream stream = input.Value;
stream.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[10];
while (stream.Read(buffer, 0, buffer.Length) == buffer.Length) { }
}
Sample Output
// *** ParamWrapper Sample *** Job=Dry Toolchain=InProcessEmitToolchain IterationCount=1 LaunchCount=1 RunStrategy=ColdStart UnrollFactor=1 WarmupCount=1 | Method | input | Mean | Error | |----------- |----------------------- |---------:|------:| | NotWrapped | System.IO.MemoryStream | 452.0 μs | NA | | NotWrapped | System.IO.MemoryStream | 203.7 μs | NA | | Wrapped | big stream | 449.4 μs | NA | | Wrapped | small stream | 213.8 μs | NA | input : Value of the 'input' parameter Mean : Arithmetic mean of all measurements Error : Half of 99.9% confidence interval 1 μs : 1 Microsecond (0.000001 sec)
Constructors
ParamWrapper(T, String)
Initializes a new instance of the ParamWrapper<T> class with the given strongly typed value and display text.
Declaration
public ParamWrapper(T value, string displayText)
Parameters
Type | Name | Description |
---|---|---|
T | value | The parameter or argument value to wrap. |
String | displayText | The associated text to display in logs and summaries. |
Fields
DisplayText
The associated text to display in logs and summaries.
Declaration
public string DisplayText
Field Value
Type | Description |
---|---|
String |
Value
The strongly typed parameter or argument value.
Declaration
public T Value
Field Value
Type | Description |
---|---|
T |
Methods
Dispose()
Disposes the wrapped value if it implements IDisposable.
Declaration
public void Dispose()
ToString()
Returns a string that represents the wrapped value.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |