Beispiel #1
0
        public void Serialize_Family_Slim()
        {
            const int CNT = 250000;

            var row = getFamily();

            var slim = new NFX.Serialization.Slim.SlimSerializer(NFX.Serialization.Slim.TypeRegistry.BoxedCommonNullableTypes,
                                                                 NFX.Serialization.Slim.TypeRegistry.BoxedCommonTypes,
                                                                 new [] { typeof(SimplePersonRow), typeof(SimplePersonRow[]), typeof(List <SimplePersonRow>), typeof(FamilyRow) });

            slim.TypeMode = NFX.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));
            }
        }
Beispiel #2
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 NFX.Serialization.Slim.SlimSerializer(NFX.Serialization.Slim.TypeRegistry.BoxedCommonNullableTypes,
                                                                     NFX.Serialization.Slim.TypeRegistry.BoxedCommonTypes,
                                                                     new [] { typeof(SimplePersonRow), typeof(SimplePersonRow[]), typeof(List <SimplePersonRow>), typeof(FamilyRow) });

                slim.TypeMode = NFX.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)));
        }
Beispiel #3
0
        public void WrappedExceptionData_Slim()
        {
            try
            {
                throw new NFXException("Oy vei!", new NFXException("Inside"))
                      {
                          Code = 223322, Source = "Karlson"
                      };
            }
            catch (Exception caught)
            {
                var wed = new WrappedExceptionData(caught);
                var ser = new NFX.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);
                }
            }
        }
Beispiel #4
0
        private static void bodySlimSerializer(int CNT, object payload)
        {
            var ms   = new System.IO.MemoryStream();
            var ser1 = new NFX.Serialization.Slim.SlimSerializer();

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

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

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

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

            bodyCore(ms, CNT, payload, ser1, ser2);
        }
Beispiel #5
0
        public void Write(string name, object value)
        {
            write(name, value, v =>
            {
                using (var ms = new MemoryStream())
                    using (var reader = new BinaryReader(ms))
                    {
                        var slim = new NFX.Serialization.Slim.SlimSerializer(NFX.IO.SlimFormat.Instance);
                        slim.Serialize(ms, v);
                        var len     = ms.Position;
                        ms.Position = 0;
                        var str     = Convert.ToBase64String(reader.ReadBytes((int)len), Base64FormattingOptions.None);

                        m_Writer.WriteLine(str);
                    }
            });
        }
Beispiel #6
0
        public void Serialize(System.IO.Stream stream)
        {
            var serializer = new NFX.Serialization.Slim.SlimSerializer(NFX.IO.SlimFormat.Instance);

            serializer.Serialize(stream, this);
        }