Exemplo n.º 1
0
        public void Performance_SimpleFlatClass()
        {
            var serializationTime   = new Stopwatch();
            var deserializationTime = new Stopwatch();
            var expected            = SimpleFlatClass.Create();
            var serializer          = AvroSerializer.Create <SimpleFlatClass>(new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            });

            using (var stream = new MemoryStream())
            {
                serializationTime.Start();
                for (var i = 0; i < NumberOfRuns; i++)
                {
                    serializer.Serialize(stream, expected);
                }
                serializationTime.Stop();

                stream.Seek(0, SeekOrigin.Begin);

                deserializationTime.Start();
                for (var i = 0; i < NumberOfRuns; i++)
                {
                    var deserialized = serializer.Deserialize(stream);
                }
                deserializationTime.Stop();

                Console.WriteLine(serializationTime.ElapsedTicks);
                Console.WriteLine(deserializationTime.ElapsedTicks);
            }
        }
Exemplo n.º 2
0
 public static ComplexNestedClass Create()
 {
     return(new ComplexNestedClass
     {
         NestedField = SimpleFlatClass.Create(),
         IntNestedField = R.Next(),
         RecursiveField = Recursive.Create()
     });
 }