mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +01:00
47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
using BenchmarkDotNet.Jobs;
|
|
using Capnp.Rpc;
|
|
using CapnpGen;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Benchmark
|
|
{
|
|
public class CapnpBenchmark
|
|
{
|
|
[Params(20, 200, 2000, 20000, 200000, 2000000)]
|
|
public int PayloadBytes;
|
|
|
|
TcpRpcClient _client;
|
|
IEchoer _echoer;
|
|
byte[] _payload;
|
|
|
|
[GlobalSetup]
|
|
public void Setup()
|
|
{
|
|
_client = new TcpRpcClient("localhost", 5002);
|
|
_client.WhenConnected.Wait();
|
|
_echoer = _client.GetMain<IEchoer>();
|
|
_payload = new byte[PayloadBytes];
|
|
new Random().NextBytes(_payload);
|
|
}
|
|
|
|
[GlobalCleanup]
|
|
public void Cleanup()
|
|
{
|
|
_echoer.Dispose();
|
|
_client.Dispose();
|
|
}
|
|
|
|
[Benchmark]
|
|
public void Echo()
|
|
{
|
|
var t = _echoer.Echo(_payload);
|
|
t.Wait();
|
|
if (t.Result?.Count != _payload.Length)
|
|
throw new InvalidOperationException("Echo server malfunction");
|
|
}
|
|
}
|
|
}
|