Merge pull request #19749 from jtattermusch/parametrized_unary_call_overhead

Make UnaryCallOverheadBenchmark parametrized
pull/19672/head
Jan Tattermusch 5 years ago committed by GitHub
commit 139a556431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/csharp/Grpc.Microbenchmarks/UnaryCallOverheadBenchmark.cs

@ -33,14 +33,28 @@ namespace Grpc.Microbenchmarks
public class UnaryCallOverheadBenchmark public class UnaryCallOverheadBenchmark
{ {
private static readonly Task<string> CompletedString = Task.FromResult(""); private static readonly Task<string> CompletedString = Task.FromResult("");
private static readonly byte[] EmptyBlob = new byte[0]; private static readonly Marshaller<byte[]> IdentityMarshaller = new Marshaller<byte[]>(msg => msg, payload => payload);
private static readonly Marshaller<string> EmptyMarshaller = new Marshaller<string>(_ => EmptyBlob, _ => ""); private static readonly Method<byte[], byte[]> PingMethod = new Method<byte[], byte[]>(MethodType.Unary, nameof(PingBenchmark), "Ping", IdentityMarshaller, IdentityMarshaller);
private static readonly Method<string, string> PingMethod = new Method<string, string>(MethodType.Unary, nameof(PingBenchmark), "Ping", EmptyMarshaller, EmptyMarshaller);
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] [Benchmark]
public string SyncUnaryCallOverhead() public byte[] SyncUnaryCallOverhead()
{ {
return client.Ping("", new CallOptions()); return client.Ping(payload, new CallOptions());
} }
Channel channel; Channel channel;
@ -81,7 +95,7 @@ namespace Grpc.Microbenchmarks
{ {
public PingClient(CallInvoker callInvoker) : base(callInvoker) { } 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); return CallInvoker.BlockingUnaryCall(PingMethod, null, options, request);
} }

Loading…
Cancel
Save