Benchmark kaput
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using mROA.Abstract;
|
||||
using mROA.Codegen;
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Benchmark;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
[DisassemblyDiagnoser]
|
||||
public class MethodAccess
|
||||
{
|
||||
private CollectableMethodRepository _current = new();
|
||||
private FastMethodRepository _fast = new();
|
||||
private readonly int _count = new GeneratedInvokersCollection().Count;
|
||||
[GlobalSetup]
|
||||
public void SetupMethodAccess()
|
||||
{
|
||||
_current.AppendInvokers(new GeneratedInvokersCollection());
|
||||
_fast.AppendInvokers(new GeneratedInvokersCollection());
|
||||
}
|
||||
|
||||
// [Benchmark(Baseline = true)]
|
||||
// public IMethodInvoker CurrentSingle()
|
||||
// {
|
||||
// return _current.GetMethod(0);
|
||||
// }
|
||||
//
|
||||
// [Benchmark]
|
||||
// public IMethodInvoker CurrentDispose()
|
||||
// {
|
||||
// return _current.GetMethod(-1);
|
||||
// }
|
||||
//
|
||||
// [Benchmark]
|
||||
// public IMethodInvoker FastSingle()
|
||||
// {
|
||||
// return _fast.GetMethod(0);
|
||||
// }
|
||||
//
|
||||
// [Benchmark]
|
||||
// public IMethodInvoker FastDispose()
|
||||
// {
|
||||
// return _fast.GetMethod(-1);
|
||||
// }
|
||||
// [Benchmark]
|
||||
// public IMethodInvoker FastSingleBaked()
|
||||
// {
|
||||
// return _fast.GetMethodBaked(0);
|
||||
// }
|
||||
//
|
||||
// [Benchmark]
|
||||
// public IMethodInvoker FastDisposeBaked()
|
||||
// {
|
||||
// return _fast.GetMethodBaked(-1);
|
||||
// }
|
||||
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public IMethodInvoker CurrentAll()
|
||||
{
|
||||
IMethodInvoker inv = null;
|
||||
for (int i = -1; i < _count; i++)
|
||||
{
|
||||
inv = _current.GetMethod(i);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public IMethodInvoker FastAll()
|
||||
{
|
||||
IMethodInvoker inv = null;
|
||||
for (int i = -1; i < _count; i++)
|
||||
{
|
||||
inv = _fast.GetMethod(i);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public IMethodInvoker FastAllBaked()
|
||||
{
|
||||
IMethodInvoker inv = null;
|
||||
for (int i = -1; i < _count; i++)
|
||||
{
|
||||
inv = _fast.GetMethodBaked(i);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
internal class FastMethodRepository: IMethodRepository
|
||||
{
|
||||
private readonly List<IMethodInvoker> _methods = [MethodInvoker.Dispose];
|
||||
private IMethodInvoker[] _baked = [];
|
||||
public void AppendInvokers(IEnumerable<IMethodInvoker> methodInvokers)
|
||||
{
|
||||
_methods.AddRange(methodInvokers);
|
||||
_baked = _methods.ToArray();
|
||||
}
|
||||
public IMethodInvoker GetMethod(int id)
|
||||
{
|
||||
return _methods[id + 1];
|
||||
}
|
||||
|
||||
public IMethodInvoker GetMethodBaked(int id)
|
||||
{
|
||||
return _baked[id + 1];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
using BenchmarkDotNet.Running;
|
||||
using mROA.Benchmark;
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
Console.WriteLine("Hello, Performance!");
|
||||
|
||||
BenchmarkRunner.Run<InvokePerformance>();
|
||||
BenchmarkRunner.Run<MethodAccess>();
|
||||
@@ -0,0 +1,73 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Benchmark;
|
||||
|
||||
public class StackOperations
|
||||
{
|
||||
private Stack<StackFrame> stack = new();
|
||||
|
||||
|
||||
|
||||
public StackOperations()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Stack()
|
||||
{
|
||||
|
||||
}
|
||||
private readonly struct StackFrame
|
||||
{
|
||||
public StackFrame(
|
||||
CborMajorType? type,
|
||||
int frameOffset,
|
||||
int? definiteLength,
|
||||
int itemsWritten,
|
||||
int? currentKeyOffset,
|
||||
int? currentValueOffset,
|
||||
List<int>? keyValuePairEncodingRanges,
|
||||
HashSet<(int Offset, int Length)>? keyEncodingRanges)
|
||||
{
|
||||
MajorType = type;
|
||||
FrameOffset = frameOffset;
|
||||
DefiniteLength = definiteLength;
|
||||
ItemsWritten = itemsWritten;
|
||||
CurrentKeyOffset = currentKeyOffset;
|
||||
CurrentValueOffset = currentValueOffset;
|
||||
KeyValuePairEncodingRanges = keyValuePairEncodingRanges;
|
||||
KeyEncodingRanges = keyEncodingRanges;
|
||||
}
|
||||
|
||||
public CborMajorType? MajorType { get; }
|
||||
public int FrameOffset { get; }
|
||||
public int? DefiniteLength { get; }
|
||||
public int ItemsWritten { get; }
|
||||
|
||||
public int? CurrentKeyOffset { get; }
|
||||
public int? CurrentValueOffset { get; }
|
||||
public List<int>? KeyValuePairEncodingRanges { get; }
|
||||
public HashSet<(int Offset, int Length)>? KeyEncodingRanges { get; }
|
||||
}
|
||||
}
|
||||
|
||||
internal enum CborMajorType
|
||||
{
|
||||
Unknown,
|
||||
Int8,
|
||||
Int16,
|
||||
Int32,
|
||||
Int64,
|
||||
UInt8,
|
||||
UInt16,
|
||||
UInt32,
|
||||
UInt64,
|
||||
Float32,
|
||||
Float64,
|
||||
Double,
|
||||
Double2,
|
||||
Double3,
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Example.Shared\Example.Shared.csproj" />
|
||||
<ProjectReference Include="..\mROA.Cbor\mROA.Cbor.csproj" />
|
||||
<ProjectReference Include="..\mROA\mROA.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user