Skip to content

Commit

Permalink
Added TraceRoute roundtrip benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed Jun 10, 2024
1 parent ef66199 commit 0cb5453
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions TestData/YangSource/YangSource.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand Down
50 changes: 50 additions & 0 deletions benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Ietf.Inet.Types;
using Yang.Attributes;
using YangParser;
using YangParser.Parser;
using YangParser.SemanticModel;
using YangSource;

namespace Benchmarks;

Expand All @@ -17,6 +19,34 @@ public class ParsingBenchmarks
private IStatement model;
private Ietf.Bfd.Ip.Mh.YangNode.MultihopNotification notification;
private string serialized;
private IYangServer server;
private IChannel channel;

private static readonly Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput input =
new()
{
MaNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MaNameString(),
MdNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MdNameString(),
Ttl = 2,
Count = 4,
Interval = 6,
CosId = 2,
DestinationMep = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer
{
MepAddress =
new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer.MepAddressChoice
{
IpAddressCaseValue =
new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer.
MepAddressChoice.IpAddressCaseValueCase
{
IpAddress = new YangNode.IpAddress(new YangNode.Ipv4Address("1.2.3.4"))
}
}
},
SourceMepValue = new(),
CommandSubType = Ietf.Connection.Oriented.Oam.YangNode.CommandSubTypeIdentity.Proactive
};

[GlobalSetup]
public void Setup()
Expand All @@ -31,6 +61,8 @@ public void Setup()
SourceAddr = new YangNode.IpAddress(new YangNode.Ipv4Address("2.3.4.5"))
};
serialized = notification.ToXML().Result;
server = new ExampleYangServer();
channel = new BenchmarkingChannel(server);
}

[Benchmark]
Expand Down Expand Up @@ -68,6 +100,24 @@ public MemoryStream ToMemoryStream()
using var ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
return await Ietf.Bfd.Ip.Mh.YangNode.MultihopNotification.ParseAsync(ms);
}

[Benchmark]
public async Task<Ietf.Connection.Oriented.Oam.YangNode.TracerouteOutput> TracerouteRoundTrip()
{
return await Ietf.Connection.Oriented.Oam.YangNode.Traceroute(channel, 123, input);
}
}

internal class BenchmarkingChannel(IYangServer server) : IChannel
{
public async Task<Stream> Send(string xml)
{
using var input = new MemoryStream(Encoding.UTF8.GetBytes(xml));
var output = new MemoryStream();
await server.Receive(input, output);
output.Seek(0, SeekOrigin.Begin);
return output;
}
}

internal static class Program
Expand Down

0 comments on commit 0cb5453

Please sign in to comment.