attempt to fix the utf-8 encode benchmark; not currently working

pull/19515/head
mgravell 6 years ago
parent dbef6c9c70
commit f53d844da9
  1. 17
      plugins.vcxproj.filters
  2. 6
      src/csharp/Grpc.Core.Tests/Properties/AssemblyInfo.cs
  3. 1
      src/csharp/Grpc.Microbenchmarks/Grpc.Microbenchmarks.csproj
  4. 47
      src/csharp/Grpc.Microbenchmarks/Utf8Encode.cs

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<CustomBuild Include="C:\Code\grpc\CMakeFiles\abdb608b4c8dfad7a28f7c47cf039774\plugins.rule">
<Filter>CMake Rules</Filter>
</CustomBuild>
<CustomBuild Include="C:\Code\grpc\CMakeLists.txt" />
</ItemGroup>
<ItemGroup>
<None Include="C:\Code\grpc\CMakeFiles\plugins" />
</ItemGroup>
<ItemGroup>
<Filter Include="CMake Rules">
<UniqueIdentifier>{870DBD13-69C5-3F27-A253-623E8947E2E7}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

@ -27,9 +27,3 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("Grpc.Microbenchmarks,PublicKey=" +
"00240000048000009400000006020000002400005253413100040000010001002f5797a92c6fcde81bd4098f43" +
"0442bb8e12768722de0b0cb1b15e955b32a11352740ee59f2c94c48edc8e177d1052536b8ac651bce11ce5da3a" +
"27fc95aff3dc604a6971417453f9483c7b5e836756d5b271bf8f2403fe186e31956148c03d804487cf642f8cc0" +
"71394ee9672dfe5b55ea0f95dfd5a7f77d22c962ccf51320d3")]

@ -11,7 +11,6 @@
<ItemGroup>
<ProjectReference Include="../Grpc.Core/Grpc.Core.csproj" />
<ProjectReference Include="../Grpc.Core.Tests/Grpc.Core.Tests.csproj" />
</ItemGroup>
<ItemGroup>

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using BenchmarkDotNet.Attributes;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Internal.Tests;
namespace Grpc.Microbenchmarks
{
@ -12,9 +10,7 @@ namespace Grpc.Microbenchmarks
[MemoryDiagnoser] // allocations
public class Utf8Encode : ISendStatusFromServerCompletionCallback
{
static readonly NativeMethods Native = NativeMethods.Get();
[Params(0, 1, 4, 128, 1024)]
[Params(0)] //, 1, 4, 128, 1024)]
public int PayloadSize { get; set; }
static readonly Dictionary<int, string> Payloads = new Dictionary<int, string> {
@ -36,22 +32,50 @@ namespace Grpc.Microbenchmarks
return new string(chars);
}
private GrpcEnvironment environment;
[GlobalSetup]
public void Setup()
{
Native.grpcsharp_test_override_method("grpcsharp_call_start_batch", "nop");
var native = NativeMethods.Get();
// ??? throws ???
native.grpcsharp_test_override_method(nameof(NativeMethods.grpcsharp_call_send_status_from_server), "nop");
environment = GrpcEnvironment.AddRef();
metadata = MetadataArraySafeHandle.Create(Metadata.Empty);
call = new FakeNativeCall();
var completionRegistry = new CompletionRegistry(environment, () => environment.BatchContextPool.Lease(), () => throw new NotImplementedException());
var cq = CompletionQueueSafeHandle.CreateAsync(completionRegistry);
call = CreateFakeCall(cq);
}
private static CallSafeHandle CreateFakeCall(CompletionQueueSafeHandle cq)
{
var call = CallSafeHandle.CreateFake(new IntPtr(0xdead), cq);
bool success = false;
while (!success)
{
// avoid calling destroy on a nonexistent grpc_call pointer
call.DangerousAddRef(ref success);
}
return call;
}
[GlobalCleanup]
public void Cleanup()
{
metadata.Dispose();
metadata?.Dispose();
metadata = null;
call.Dispose();
call?.Dispose();
call = null;
if (environment != null)
{
environment = null;
GrpcEnvironment.ReleaseAsync().Wait();
}
}
private INativeCall call;
private CallSafeHandle call;
private MetadataArraySafeHandle metadata;
const int Iterations = 1000;
@ -62,8 +86,7 @@ namespace Grpc.Microbenchmarks
var status = new Status(StatusCode.OK, payload);
for (int i = 0; i < Iterations; i++)
{
call.StartSendStatusFromServer(this, status,
metadata, false, null, WriteFlags.NoCompress);
call.StartSendStatusFromServer(this, status, metadata, false, null, WriteFlags.NoCompress);
}
}

Loading…
Cancel
Save