示例#1
0
        static StructSerializeBenchmark()
        {
            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntStruct> >();
            HagarData       = new byte[1000];
            Session         = services.GetRequiredService <SessionPool>().GetSession();

            // 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>();
        }
        static ClassSerializeBenchmark()
        {
            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntClass> >();
            Session         = services.GetRequiredService <SerializerSessionPool>().GetSession();
            HagarData       = new byte[1000];

            HyperionSession = HyperionSerializer.GetSerializerSession();

            SystemTextJsonWriter = new Utf8JsonWriter(SystemTextJsonOutput);
        }
示例#3
0
        static DeserializeBenchmark()
        {
            ProtoInput = new MemoryStream();
            ProtoBuf.Serializer.Serialize(ProtoInput, IntClass.Create());

            HyperionInput = new MemoryStream();
            HyperionSerializer.Serialize(IntClass.Create(), HyperionInput);

            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntClass> >();
            var bytes = new byte[1000];

            Session = services.GetRequiredService <SessionPool>().GetSession();
            var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session);

            HagarSerializer.Serialize(ref writer, IntClass.Create());
            HagarInput = 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(IntClass.Create(), writer2);
            OrleansInput  = writer2.ToBytes();
            OrleansBuffer = new BinaryTokenStreamReader(OrleansInput);
        }
示例#4
0
        static SerializeBenchmark()
        {
            // Hagar
            var services = new ServiceCollection()
                           .AddHagar()
                           .AddSerializers(typeof(Program).Assembly)
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntClass> >();
            Session         = services.GetRequiredService <SessionPool>().GetSession();
            HagarData       = new byte[1000];

            // Orleans
            OrleansSerializer = new ClientBuilder()
                                .ConfigureDefaults()
                                .UseLocalhostClustering()
                                .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>();
        }
        static ClassDeserializeBenchmark()
        {
            ProtoInput = new MemoryStream();
            ProtoBuf.Serializer.Serialize(ProtoInput, IntClass.Create());

            HyperionInput   = new MemoryStream();
            HyperionSession = HyperionSerializer.GetDeserializerSession();
            HyperionSerializer.Serialize(IntClass.Create(), HyperionInput);

            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntClass> >();
            var bytes = new byte[1000];

            Session = services.GetRequiredService <SerializerSessionPool>().GetSession();
            var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session);

            //HagarSerializer.Serialize(ref writer, IntClass.Create());
            writer.WriteStartObject(0, typeof(IntClass), typeof(IntClass));
            Generated.Serialize(ref writer, IntClass.Create());
            writer.WriteEndObject();
            HagarInput = bytes;

            Utf8JsonInput = Utf8JsonNS.JsonSerializer.Serialize(IntClass.Create(), Utf8JsonResolver);

            var stream = new MemoryStream();

            using (var jsonWriter = new System.Text.Json.Utf8JsonWriter(stream))
            {
                System.Text.Json.JsonSerializer.Serialize <IntClass>(jsonWriter, IntClass.Create());
            }

            SystemTextJsonInput = stream.ToArray();
        }
        static StructDeserializeBenchmark()
        {
            ProtoObj = new MemoryStream();
            ProtoBuf.Serializer.Serialize(ProtoObj, new IntStruct());

            HyperionObj = new MemoryStream();
            HyperionSerializer.Serialize(new IntStruct(), HyperionObj);

            // Hagar
            var services = new ServiceCollection()
                           .AddHagar()
                           .AddSerializers(typeof(Program).Assembly)
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntStruct> >();
            HagarData       = new SingleSegmentBuffer();
            var writer = new Writer(HagarData);

            Session = services.GetRequiredService <SessionPool>().GetSession();
            HagarSerializer.Serialize(new IntStruct(), Session, ref writer);

            // Orleans
            OrleansSerializer = new ClientBuilder()
                                .ConfigureDefaults()
                                .UseLocalhostClustering()
                                .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(new IntStruct(), writer2);
            OrleansData   = writer2.ToBytes();
            OrleansBuffer = new BinaryTokenStreamReader(OrleansData);
        }
        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();
        }
示例#8
0
 private void ReturnSession(SerializerSession session) => _sessionPool.Return(session);