private static int SumResult(IntStruct result) { return(result.MyProperty1 + result.MyProperty2 + result.MyProperty3 + result.MyProperty4 + result.MyProperty5 + result.MyProperty6 + result.MyProperty7 + result.MyProperty8 + result.MyProperty9); }
static StructDeserializeBenchmark() { ProtoInput = new MemoryStream(); ProtoBuf.Serializer.Serialize(ProtoInput, IntStruct.Create()); HyperionInput = new MemoryStream(); HyperionSerializer.Serialize(IntStruct.Create(), HyperionInput); // Hagar var services = new ServiceCollection() .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly)) .BuildServiceProvider(); HagarSerializer = services.GetRequiredService <Serializer <IntStruct> >(); Session = services.GetRequiredService <SessionPool>().GetSession(); var bytes = new byte[1000]; var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session); HagarSerializer.Serialize(ref writer, IntStruct.Create()); HagarInput = new ReadOnlySequence <byte>(bytes); // Orleans OrleansSerializer = new ClientBuilder() .ConfigureDefaults() .UseLocalhostClustering() .ConfigureServices(s => s.ToList().ForEach(r => { if (r.ServiceType == typeof(IConfigurationValidator)) { s.Remove(r); } })) .Configure <ClusterOptions>(o => o.ClusterId = o.ServiceId = "test") .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(SimpleClass).Assembly).WithCodeGeneration()) .Configure <SerializationProviderOptions>(options => options.FallbackSerializationProvider = typeof(SupportsNothingSerializer).GetTypeInfo()) .Build().ServiceProvider.GetRequiredService <SerializationManager>(); var writer2 = new BinaryTokenStreamWriter(); OrleansSerializer.Serialize(IntStruct.Create(), writer2); OrleansInput = writer2.ToBytes(); OrleansBuffer = new BinaryTokenStreamReader(OrleansInput); }
static StructDeserializeBenchmark() { ProtoInput = new MemoryStream(); ProtoBuf.Serializer.Serialize(ProtoInput, IntStruct.Create()); HyperionInput = new MemoryStream(); HyperionSerializer.Serialize(IntStruct.Create(), HyperionInput); // Hagar var services = new ServiceCollection() .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly)) .BuildServiceProvider(); HagarSerializer = services.GetRequiredService <ValueSerializer <IntStruct> >(); Session = services.GetRequiredService <SerializerSessionPool>().GetSession(); var bytes = new byte[1000]; var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session); IntStruct intStruct = IntStruct.Create(); HagarSerializer.Serialize(ref intStruct, ref writer); HagarHandCraftedSerializer = new HagarGen_Serializer_IntStruct_1843466(); HagarInput = bytes; HyperionSession = HyperionSerializer.GetDeserializerSession(); Utf8JsonInput = Utf8JsonNS.JsonSerializer.Serialize(IntStruct.Create(), Utf8JsonResolver); var stream = new MemoryStream(); using (var jsonWriter = new System.Text.Json.Utf8JsonWriter(stream)) { System.Text.Json.JsonSerializer.Serialize <IntStruct>(jsonWriter, IntStruct.Create()); } SystemTextJsonInput = stream.ToArray(); }