Esempio n. 1
0
        public void Test()
        {
            const int len    = 10000;
            const int repeat = 100;

            var stream = new MemoryStream(750 * 1024);

            long totalTicksSeri   = 0;
            long totalTicksDeseri = 0;

            for (int i = 0; i < repeat; ++i)
            {
                stream.Seek(0, SeekOrigin.Begin);
                var listA = MakeTestData(len);
                var sw    = Stopwatch.StartNew();

                VariableValue_Serializer.Serialize(stream, listA, Common.CurrentBinaryVersion);
                //StdJson.ObjectToStream(listA, stream);

                sw.Stop();
                totalTicksSeri += sw.ElapsedTicks;
                //Console.WriteLine($"{i} Dauer 1: {sw.ElapsedMilliseconds} ms {stream.Position} {listA.Count}");
                Console.WriteLine($"{stream.Position / (double)listA.Count} {listA.Count}");

                stream.Seek(0, SeekOrigin.Begin);
                sw.Restart();

                List <VariableValue> listB;
                listB = VariableValue_Serializer.Deserialize(stream);

                //using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8, leaveOpen: true)) {
                //    listB = StdJson.ObjectFromReader<List<VariableValue>>(reader);
                //}

                sw.Stop();
                totalTicksDeseri += sw.ElapsedTicks;

                bool ok = listA.Count == listB.Count && Enumerable.Range(0, listA.Count).All(x => listA[x] == listB[x]);
                if (!ok)
                {
                    throw new Exception("Test failed!");
                }
                //Console.WriteLine($"{i} Dauer 2: {sw.ElapsedMilliseconds} ms {ok}\n");

                if (i == 0)
                {
                    totalTicksSeri   = 0;
                    totalTicksDeseri = 0;
                }
            }

            console.WriteLine(Util.FormatDuration("Serial", totalTicksSeri, repeat));
            console.WriteLine(Util.FormatDuration("Deseri", totalTicksDeseri, repeat));
        }
Esempio n. 2
0
        public void BinSerialize(BinaryWriter writer, byte binaryVersion)
        {
            BaseBinSerialize(writer, binaryVersion);

            writer.Write(MemberPresent);
            VariableValue_Serializer.Serialize(writer, Values, binaryVersion);

            writer.Write(Timeout.HasValue ? MemberPresent : MemberNull);
            if (Timeout.HasValue)
            {
                writer.Write((long)Timeout.Value.TotalMilliseconds);
            }
        }
Esempio n. 3
0
        public void BinSerialize(BinaryWriter writer, byte binaryVersion)
        {
            if (Values == null)
            {
                throw new Exception($"Failed to serialize {GetType().Name}: Values may not be null!");
            }
            BaseBinSerialize(writer, binaryVersion);

            writer.Write(MemberPresent);
            VariableValue_Serializer.Serialize(writer, Values, binaryVersion);

            writer.Write(Timeout.HasValue ? MemberPresent : MemberNull);
            if (Timeout.HasValue)
            {
                writer.Write((long)Timeout.Value.TotalMilliseconds);
            }
        }
Esempio n. 4
0
 public void BinSerialize(BinaryWriter writer, byte binaryVersion)
 {
     BaseBinSerialize(writer, binaryVersion);
     writer.Write(MemberPresent);
     VariableValue_Serializer.Serialize(writer, Values, binaryVersion);
 }