Example #1
0
        public void CouldSerializeRegularSortedMapWithZstd()
        {
            SortedMap <DateTime, decimal> .Init();

            //BloscSettings.CompressionMethod = "zstd";
            var rng    = new Random();
            var buffer = new byte[10000];
            var sm     = new SortedMap <DateTime, decimal>();

            for (var i = 0; i < 1; i++)
            {
                sm.Add(DateTime.Today.AddSeconds(i), (decimal)Math.Round(i + rng.NextDouble(), 2));
            }

            MemoryStream tmp;
            var          size = BinarySerializer.SizeOf(sm, out tmp, CompressionMethod.Zstd);
            var          len  = BinarySerializer.Write(sm, buffer, 0, tmp);

            Console.WriteLine($"Useful: {sm.Count * 24}");
            Console.WriteLine($"Total: {len}");
            // NB interesting that with converting double to decimal savings go from 65% to 85%,
            // even calculated from (8+8) base size not decimal's 16 size
            Console.WriteLine($"Savings: {1.0 - ((len * 1.0) / (sm.Count * 24.0))}");
            SortedMap <DateTime, decimal> sm2 = null;
            var len2 = BinarySerializer.Read(buffer, 0, out sm2);

            Assert.AreEqual(len, len2);

            Assert.IsTrue(sm2.Keys.SequenceEqual(sm.Keys));
            Assert.IsTrue(sm2.Values.SequenceEqual(sm.Values));
        }
Example #2
0
        public void CouldSerializeSortedMapWithBinary()
        {
            SortedMap <DateTime, double> .Init();

            var sm = new SortedMap <DateTime, double>();

            for (int i = 0; i < 10; i++)
            {
                sm.Add(DateTime.UtcNow.Date.AddDays(i), i);
            }
            MemoryStream tmp;
            var          len = BinarySerializer.SizeOf(sm, out tmp);

            Console.WriteLine(len);
            var dest = BufferPool.PreserveMemory(len);
            var len2 = BinarySerializer.Write(sm, ref dest, 0, tmp);

            Assert.AreEqual(len, len2);

            SortedMap <DateTime, double> sm2 = null;

            BinarySerializer.Read <SortedMap <DateTime, double> >(dest, 0, out sm2);

            Assert.IsTrue(sm.SequenceEqual(sm2));
        }
Example #3
0
        public unsafe void CouldSerializeSortedMap()
        {
            SortedMap <DateTime, decimal> .Init();

            var rng = new Random();

            var dest   = (Memory <byte>) new byte[1000000];
            var buffer = dest;
            var handle = buffer.Pin();
            var ptr    = (IntPtr)handle.Pointer;

            var sm = new SortedMap <DateTime, decimal>();

            for (var i = 0; i < 10000; i++)
            {
                if (i != 2)
                {
                    sm.Add(DateTime.Today.AddHours(i), (decimal)Math.Round(i + rng.NextDouble(), 2));
                }
            }
            var len = BinarySerializer.Write(sm, buffer, format: SerializationFormat.BinaryZstd);

            Console.WriteLine($"Useful: {sm.Count * 24.0}");
            Console.WriteLine($"Total: {len}");
            // NB interesting that with converting double to decimal savings go from 65% to 85%,
            // even calculated from (8+8) base size not decimal's 16 size
            Console.WriteLine($"Savings: {1.0 - ((len * 1.0) / (sm.Count * 24.0))}");
            SortedMap <DateTime, decimal> sm2 = null;
            var len2 = BinarySerializer.Read(buffer, out sm2);

            Assert.AreEqual(len, len2);

            Assert.IsTrue(sm2.Keys.SequenceEqual(sm.Keys));
            Assert.IsTrue(sm2.Values.SequenceEqual(sm.Values));
        }
Example #4
0
        public void CouldSerializeSortedMap2()
        {
            SortedMap <int, int> .Init();

            var rng    = new Random();
            var buffer = new byte[100000];
            var sm     = new SortedMap <int, int>();

            for (var i = 0; i < 10000; i++)
            {
                sm.Add(i, i);
            }
            MemoryStream temp;
            var          len  = BinarySerializer.SizeOf(sm, out temp, CompressionMethod.LZ4);
            var          len2 = BinarySerializer.Write(sm, buffer, 0, temp, CompressionMethod.LZ4);

            Assert.AreEqual(len, len2);
            Console.WriteLine($"Useful: {sm.Count * 8}");
            Console.WriteLine($"Total: {len}");
            // NB interesting that with converting double to decimal savings go from 65% to 85%,
            // even calculated from (8+8) base size not decimal's 16 size
            Console.WriteLine($"Savings: {1.0 - ((len * 1.0) / (sm.Count * 8.0))}");
            SortedMap <int, int> sm2 = null;
            var len3 = BinarySerializer.Read(buffer, 0, out sm2);

            Assert.AreEqual(len, len3);

            Assert.IsTrue(sm2.Keys.SequenceEqual(sm.Keys));
            Assert.IsTrue(sm2.Values.SequenceEqual(sm.Values));
        }
Example #5
0
        public void CouldSerializeSortedMap()
        {
            SortedMap <DateTime, decimal> .Init();

            var rng = new Random();
            var ptr = Marshal.AllocHGlobal(100000);
            var db  = new DirectBuffer(100000, ptr);
            var sm  = new SortedMap <DateTime, decimal>();

            for (var i = 0; i < 10000; i++)
            {
                sm.Add(DateTime.Today.AddHours(i), (decimal)Math.Round(i + rng.NextDouble(), 2));
            }
            var len = BinarySerializer.Write(sm, ref db, compression: CompressionMethod.Zstd);

            Console.WriteLine($"Useful: {sm.Count * 24.0}");
            Console.WriteLine($"Total: {len}");
            // NB interesting that with converting double to decimal savings go from 65% to 85%,
            // even calculated from (8+8) base size not decimal's 16 size
            Console.WriteLine($"Savings: {1.0 - ((len * 1.0) / (sm.Count * 24.0))}");
            SortedMap <DateTime, decimal> sm2 = null;
            var len2 = BinarySerializer.Read(db, 0, ref sm2);

            Assert.AreEqual(len, len2);

            Assert.IsTrue(sm2.Keys.SequenceEqual(sm.Keys));
            Assert.IsTrue(sm2.Values.SequenceEqual(sm.Values));
        }