Prepare for many parsers

This commit is contained in:
2025-08-06 14:32:48 +03:00
parent 2cbcc6b201
commit 304811c964
6 changed files with 84 additions and 21 deletions
+37
View File
@@ -0,0 +1,37 @@
using BenchmarkDotNet.Attributes;
using mROA.Implementation;
namespace mROA.Benchmark;
public class IdGeneration
{
public static int X = 0;
[Benchmark]
public Guid GuidGeneration()
{
return Guid.NewGuid();
}
[Benchmark(Baseline = true)]
public RequestId ReqIdGeneration()
{
return RequestId.Generate();
}
[Benchmark]
public RequestId ReqIdIfGeneration()
{
var reqId = RequestId.Generate();
if (++X % 2 == 0)
{
reqId.P0 = 0;
}
else
{
reqId.P1 = 0;
}
return reqId;
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ using mROA.Implementation;
Console.WriteLine("Hello, World!");
var test = new CborTest();
test.ArrayWrite();
BenchmarkRunner.Run<VirtualOverhead>();
BenchmarkRunner.Run<IdGeneration>();
public static class CborExtensions
{
+39 -18
View File
@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using mROA.Implementation;
@@ -5,17 +6,15 @@ namespace mROA.Benchmark;
public class VirtualOverhead
{
private ICallRequest _request;
private CallRequest _directRequest;
private RawCallRequest _rawRequest;
public VirtualOverhead()
{
_request = new CallRequest
[GlobalSetup]
public void Setup() {
_directRequest = new CallRequest
{
CommandId = 5, Id = new RequestId(), ObjectId = ComplexObjectIdentifier.Null, Parameters = null
};
_directRequest = (CallRequest)_request;
_rawRequest = new RawCallRequest
{
CommandId = _directRequest.CommandId, Id = _directRequest.Id, ObjectId = _directRequest.ObjectId,
@@ -24,18 +23,6 @@ public class VirtualOverhead
}
[Benchmark(Baseline = true)]
public long VirtualUsage()
{
var req = _request;
long acc = 0;
acc += req.CommandId;
acc += (long)(req.Id.P1 + req.Id.P0);
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
acc += (req.Parameters ?? []).Length;
return acc;
}
[Benchmark]
public long DirectUsage()
{
var req = _directRequest;
@@ -58,6 +45,40 @@ public class VirtualOverhead
acc += (req.Parameters ?? []).Length;
return acc;
}
[Benchmark]
public long ParamUsage()
{
return Call(_directRequest);
}
[Benchmark]
public long ParamInUsage()
{
return CallIn(in _directRequest);
}
[MethodImpl(MethodImplOptions.NoInlining)]
public long Call(CallRequest req)
{
long acc = 0;
acc += req.CommandId;
acc += (long)(req.Id.P1 + req.Id.P0);
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
acc += (req.Parameters ?? []).Length;
return acc;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public long CallIn(in CallRequest req)
{
long acc = 0;
acc += req.CommandId;
acc += (long)(req.Id.P1 + req.Id.P0);
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
acc += (req.Parameters ?? []).Length;
return acc;
}
}
public struct RawCallRequest