예제 #1
0
        public void Serialize_SimplePerson_Slim()
        {
            const int CNT = 250000;

            var row = getSimplePerson();

            var slim = new Azos.Serialization.Slim.SlimSerializer(Azos.Serialization.Slim.TypeRegistry.BoxedCommonNullableTypes,
                                                                  Azos.Serialization.Slim.TypeRegistry.BoxedCommonTypes,
                                                                  new [] { typeof(SimplePersonRow) });

            slim.TypeMode = Azos.Serialization.Slim.TypeRegistryMode.Batch;//give slim all possible preferences

            using (var ms = new MemoryStream())
            {
                slim.Serialize(ms, row);//warmup
                var sw = Stopwatch.StartNew();
                for (var i = 0; i < CNT; i++)
                {
                    ms.Position = 0;
                    slim.Serialize(ms, row);
                }

                var el = sw.ElapsedMilliseconds;
                Console.WriteLine("Slim did {0:n0} in {1:n0} ms at {2:n0} ops/sec. Stream Size is: {3:n0} bytes".Args(CNT, el, CNT / (el / 1000d), ms.Length));
            }
        }
예제 #2
0
        public void WrappedExceptionData_Slim()
        {
            try
            {
                throw new AzosException("Oy vei!", new AzosException("Inside"))
                      {
                          Code = 223322, Source = "Karlson"
                      };
            }
            catch (Exception caught)
            {
                var wed = new WrappedExceptionData(caught);
                var ser = new Azos.Serialization.Slim.SlimSerializer();

                using (var ms = new MemoryStream())
                {
                    ser.Serialize(ms, wed);
                    ms.Position = 0;

                    var bin = ms.ToArray();
                    Console.WriteLine();
                    Console.WriteLine($"Bin {bin.Length} bytes:");
                    Console.WriteLine($"-----------------------------");
                    Console.WriteLine(bin.ToDumpString(DumpFormat.Hex));

                    var wed2 = ser.Deserialize(ms) as WrappedExceptionData;
                    averWrappedExceptionEquality(wed, wed2);
                }
            }
        }
예제 #3
0
        public void Deserialize_Family_Slim(int CNT, int tcnt)
        {
            var row = getFamily();

            var tasks = new List <Task>();
            var sw    = Stopwatch.StartNew();

            tasks.Add(Task.Factory.StartNew(() =>
            {
                var slim = new Azos.Serialization.Slim.SlimSerializer(Azos.Serialization.Slim.TypeRegistry.BoxedCommonNullableTypes,
                                                                      Azos.Serialization.Slim.TypeRegistry.BoxedCommonTypes,
                                                                      new [] { typeof(SimplePersonRow), typeof(SimplePersonRow[]), typeof(List <SimplePersonRow>), typeof(FamilyRow) });

                slim.TypeMode = Azos.Serialization.Slim.TypeRegistryMode.Batch;//give slim all possible preferences

                using (var ms = new MemoryStream())
                {
                    slim.Serialize(ms, row);//warmup
                    for (var i = 0; i < CNT; i++)
                    {
                        ms.Position = 0;
                        var row2    = slim.Deserialize(ms) as FamilyRow;
                        Aver.AreEqual(row.ID, row2.ID);
                    }
                }
            }));

            Task.WaitAll(tasks.ToArray());

            var el    = sw.ElapsedMilliseconds;
            var total = CNT * tcnt;

            Console.WriteLine("Slim did {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(total, el, total / (el / 1000d)));
        }
예제 #4
0
        private static void bodySlimSerializer(int CNT, object payload)
        {
            var ms   = new System.IO.MemoryStream();
            var ser1 = new Azos.Serialization.Slim.SlimSerializer();

            ser1.TypeMode = Azos.Serialization.Slim.TypeRegistryMode.Batch;

            ser1.Serialize(ms, payload); //warmup outside timer

            var ser2 = new Azos.Serialization.Slim.SlimSerializer();

            ser2.TypeMode = Azos.Serialization.Slim.TypeRegistryMode.Batch;
            ms.Position   = 0;
            var got = ser2.Deserialize(ms); //warmup outside timer

            bodyCore(ms, CNT, payload, ser1, ser2);
        }