Remove ICallRequest

This commit is contained in:
2025-08-03 00:32:32 +03:00
parent 0818ed6a5a
commit 2cbcc6b201
11 changed files with 109 additions and 50 deletions
+75
View File
@@ -0,0 +1,75 @@
using BenchmarkDotNet.Attributes;
using mROA.Implementation;
namespace mROA.Benchmark;
public class VirtualOverhead
{
private ICallRequest _request;
private CallRequest _directRequest;
private RawCallRequest _rawRequest;
public VirtualOverhead()
{
_request = 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,
Parameters = null
};
}
[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;
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 RawUsage()
{
var req = _rawRequest;
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
{
public RequestId Id;
public int CommandId;
public ComplexObjectIdentifier ObjectId;
public object?[]? Parameters;
public override string ToString()
{
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
}
}