Пример #1
0
        public void CouldSerializeManySortedMaps()
        {
            var sw = new Stopwatch();

            sw.Start();

            SortedMap <DateTime, double> sortedMap = new SortedMap <DateTime, double>();

            byte[] bytes = null;
            var    rng   = new System.Random();

            for (int i = 0; i < 1000; i++)
            {
                sortedMap.Add(DateTime.UtcNow.Date.AddSeconds(i), Math.Round(i + rng.NextDouble(), 2));
                bytes = Serializer.Serialize(sortedMap);
                var sortedMap2 = Serializer.Deserialize <SortedMap <DateTime, double> >(bytes);
                Assert.AreEqual(sortedMap.Count, sortedMap2.Count);
                unsafe
                {
                    fixed(DateTime *ptr1 = &sortedMap.keys[0])
                    fixed(DateTime * ptr2 = &sortedMap2.keys[0])
                    {
                        Assert.IsTrue(BytesExtensions.UnsafeCompare((IntPtr)ptr1, (IntPtr)ptr2, sortedMap.keys.Length * 8));
                    }

                    fixed(double *ptr1 = &sortedMap.values[0])
                    fixed(double *ptr2 = &sortedMap2.values[0])
                    {
                        Assert.IsTrue(BytesExtensions.UnsafeCompare((IntPtr)ptr1, (IntPtr)ptr2, sortedMap.size * 8));
                    }
                }

                //Assert.IsTrue(sortedMap.Keys.SequenceEqual(sortedMap2.Keys));
                //Assert.IsTrue(sortedMap.Values.SequenceEqual(sortedMap2.Values));
            }
            sw.Stop();
            Console.WriteLine("Elapsed msecs: " + sw.ElapsedMilliseconds);
            Console.WriteLine("Uncompressed size: 16000");
            Console.WriteLine("Compressed size: " + bytes.Length);
        }