Make UnaryCallOverheadBenchmark parametrized

pull/19749/head
Jan Tattermusch 5 years ago
parent 05d6f9f2b1
commit 8fa870c4e5
  1. 26
      src/csharp/Grpc.Microbenchmarks/UnaryCallOverheadBenchmark.cs

@ -33,14 +33,28 @@ namespace Grpc.Microbenchmarks
public class UnaryCallOverheadBenchmark
{
private static readonly Task<string> CompletedString = Task.FromResult("");
private static readonly byte[] EmptyBlob = new byte[0];
private static readonly Marshaller<string> EmptyMarshaller = new Marshaller<string>(_ => EmptyBlob, _ => "");
private static readonly Method<string, string> PingMethod = new Method<string, string>(MethodType.Unary, nameof(PingBenchmark), "Ping", EmptyMarshaller, EmptyMarshaller);
private static readonly Marshaller<byte[]> IdentityMarshaller = new Marshaller<byte[]>(msg => msg, payload => payload);
private static readonly Method<byte[], byte[]> PingMethod = new Method<byte[], byte[]>(MethodType.Unary, nameof(PingBenchmark), "Ping", IdentityMarshaller, IdentityMarshaller);
private int payloadSize;
private byte[] payload;
// size of payload that is sent as request and received as response.
[Params(0, 1, 10, 100, 1000)]
public int PayloadSize
{
get { return payloadSize; }
set
{
payloadSize = value;
payload = new byte[value];
}
}
[Benchmark]
public string SyncUnaryCallOverhead()
public byte[] SyncUnaryCallOverhead()
{
return client.Ping("", new CallOptions());
return client.Ping(payload, new CallOptions());
}
Channel channel;
@ -81,7 +95,7 @@ namespace Grpc.Microbenchmarks
{
public PingClient(CallInvoker callInvoker) : base(callInvoker) { }
public string Ping(string request, CallOptions options)
public byte[] Ping(byte[] request, CallOptions options)
{
return CallInvoker.BlockingUnaryCall(PingMethod, null, options, request);
}

Loading…
Cancel
Save