Exemple #1
0
        public ComplexTypeBenchmarks()
        {
            _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())
                                 .Build().ServiceProvider.GetRequiredService <SerializationManager>();
            var services = new ServiceCollection();

            _ = services
                .AddHagar(hagar => hagar.AddISerializableSupport().AddAssembly(typeof(Program).Assembly));
            var serviceProvider = services.BuildServiceProvider();

            _hagarSerializer  = serviceProvider.GetRequiredService <Serializer <ComplexClass> >();
            _structSerializer = serviceProvider.GetRequiredService <Serializer <SimpleStruct> >();
            _sessionPool      = serviceProvider.GetRequiredService <SerializerSessionPool>();
            _value            = new ComplexClass
            {
                BaseInt = 192,
                Int     = 501,
                String  = "bananas",
                //Array = Enumerable.Range(0, 60).ToArray(),
                //MultiDimensionalArray = new[,] {{0, 2, 4}, {1, 5, 6}}
            };
            _value.AlsoSelf = _value.BaseSelf = _value.Self = _value;

            _structValue = new SimpleStruct
            {
                Int  = 42,
                Bool = true,
                Guid = Guid.NewGuid()
            };
            _session = _sessionPool.GetSession();
            var writer = HagarBuffer.CreateWriter(_session);

            _hagarSerializer.Serialize(_value, ref writer);
            var bytes = new byte[writer.Output.GetMemory().Length];

            writer.Output.GetReadOnlySequence().CopyTo(bytes);
            _hagarBytes = new ReadOnlySequence <byte>(bytes);
            HagarBuffer.Reset();

            var writer2 = new BinaryTokenStreamWriter();

            _orleansSerializer.Serialize(_value, writer2);
            _orleansBytes = writer2.ToBytes();

            _readBytesLength = Math.Min(bytes.Length, _orleansBytes.Sum(x => x.Count));
        }
Exemple #2
0
        public SimpleStruct HagarStructRoundTrip()
        {
            var writer = new Writer(HagarBuffer);

            session.FullReset();
            this.structSerializer.Serialize(this.structValue, session, ref writer);

            session.FullReset();
            var reader = new Reader(HagarBuffer.GetReadOnlySequence());
            var result = this.structSerializer.Deserialize(session, ref reader);

            HagarBuffer.Reset();
            return(result);
        }