Beispiel #1
0
        public long Hagar()
        {
            Session.FullReset();
            var writer = new SingleSegmentBuffer(HagarData).CreateWriter(Session);

            HagarSerializer.Serialize(ref writer, Input);
            return(writer.Output.Length);
        }
Beispiel #2
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);
        }
        static SerializeBenchmark()
        {
            // Hagar
            var services = new ServiceCollection()
                           .AddHagar()
                           .AddSerializers(typeof(Program).Assembly)
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <MsgPackInts> >();
            HagarData       = new SingleSegmentBuffer();
            Session         = services.GetRequiredService <SessionPool>().GetSession();

            // 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>();
        }
Beispiel #4
0
        private static void BenchmarkFlex(TypicalMessage message)
        {
            var serializer = new Serializer(new SerializerOptions(false, new[] { typeof(TypicalMessage) }));
            var session    = serializer.CreateSession();
            var bytes      = new byte[100];
            var b          = new SingleSegmentBuffer(bytes);
            var writer     = new Writer <SingleSegmentBuffer>(b, session);

            //warmup
            serializer.Serialize(message, ref writer);

            Console.WriteLine("Benchmarking Flex ");
            var sw = Stopwatch.StartNew();

            for (var i = 0; i < 10_000_000; i++)
            {
                serializer.Serialize(message, ref writer);
            }

            Console.WriteLine(sw.Elapsed.TotalMilliseconds);
        }
        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();
        }