Esempio n. 1
0
        public void ToString_MultipleProperties()
        {
            // Arrange

            var multiple = new MultipleProperties(
                "foo",
                42,
                new DateTime(2016, 3, 17, 12, 30, 55, 111),
                new DateTime(2006, 7, 22, 15, 30, 0), // <3
                null,
                ImmutableHashSet <Guid> .Empty
                );

            // Act

            var output = multiple.ToString();

            // Assert

            Assert.Equal(
                "{ " +
                "StringProperty: \"foo\", " +
                "IntProperty: 42, " +
                "DateTimeProperty: 2016-03-17T12:30:55.1110000, " +
                "NullableDateTimeProperty: 2006-07-22T15:30:00.0000000, " +
                "Anything: null, " +
                "Enumerable: [] }",
                output
                );
        }
        public void can_map_multiple_properties()
        {
            var input = new MultipleProperties {
                Int = 1, Long = 2, Boolean = true
            };
            var meta = new[] {
                new SqlMetaData("int", SqlDbType.Int),
                new SqlMetaData("LOng", SqlDbType.BigInt),
                new SqlMetaData("BOOLEAN", SqlDbType.Bit),
            };
            var recs = new[] { input }.ToDataRecords(meta).ToList();

            Assert.AreEqual(1, recs.Count, "Count");
            Assert.AreEqual(1, recs[0].GetValue(0));
            Assert.AreEqual(2, recs[0].GetValue(1));
            Assert.AreEqual(true, recs[0].GetValue(2));
            Assert.AreEqual(3, recs[0].FieldCount);
        }
        private static void MemorySizePerformance()
        {
            /*
             * Some numbers:
             * ---------------------------------------------------------------------------------------------------------
             * 10k objects
             * ---------------------------------------------------------------------------------------------------------
             * maxStringSize            repeatStringSize            serialized vs Raw            compression vs raw
             * 1                        1                            92.4%                        93.8%
             * 17                       1                            88.7%                        90.0%
             * 128                      1                            73.9%                        74.7%
             * 2                        2                            92.7%                        93.8%
             * 17                       2                            86.7%                        89.7%
             * 128                      2                            73.9%                        74.7%
             * 4                        4                            90.5%                        91.6%
             * 17                       4                            86.7%                        89.7%
             * 128                      4                            73.9%                        68.8%
             * 128                      128                          73.9%                        56.8%
             * 
             * 10,000                   10,000                       50.7%                         1.8%
             * 100,000                  100,000                      50.1%                         0.2%
             */

            const int MAX_STRING_SIZE = 10000;
            const int REPEAT_STRING_SIZE = 10;
            const int ITERATIONS = 1000;
            const string KEY = "impt-key";

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            long mCs = GC.GetTotalMemory(true);
            MemoryCache cM = new MemoryCache("cM");
            for (int i = 0; i < ITERATIONS; i++)
            {
                var m = new MultipleProperties
                    {
                        Id = GenerateId(),
                        Name = GenerateString(MAX_STRING_SIZE, REPEAT_STRING_SIZE)
                    };

                byte[] s = ProtoBufSerializer.Serialize(m);
                byte[] c = SmartCompressor.Instance.CompressAsync(s).Result;
                cM.Set(KEY + i.ToString(CultureInfo.InvariantCulture), c, null);
            }

            long mCe = GC.GetTotalMemory(true);
            long compressMemory = mCe - mCs;

            cM.Trim(100);
            cM.Dispose();
            // ReSharper disable once RedundantAssignment
            cM = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            long mSs = GC.GetTotalMemory(true);
            MemoryCache sM = new MemoryCache("sM");
            for (int i = 0; i < ITERATIONS; i++)
            {
                var m = new MultipleProperties
                    {
                        Id = GenerateId(),
                        Name = GenerateString(MAX_STRING_SIZE, REPEAT_STRING_SIZE)
                    };

                byte[] s = ProtoBufSerializer.Serialize(m);
                sM.Set(KEY + i.ToString(CultureInfo.InvariantCulture), s, null);
            }

            long mSe = GC.GetTotalMemory(true);
            long serializeMemory = mSe - mSs;

            sM.Trim(100);
            sM.Dispose();
            // ReSharper disable once RedundantAssignment
            sM = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            long mRs = GC.GetTotalMemory(true);
            MemoryCache rM = new MemoryCache("rM");
            for (int i = 0; i < ITERATIONS; i++)
            {
                var m = new MultipleProperties
                    {
                        Id = GenerateId(),
                        Name = GenerateString(MAX_STRING_SIZE, REPEAT_STRING_SIZE)
                    };
                rM.Set(KEY + i.ToString(CultureInfo.InvariantCulture), m, null);
            }

            long mRe = GC.GetTotalMemory(true);
            long rawMemory = mRe - mRs;

            rM.Trim(100);
            rM.Dispose();
            // ReSharper disable once RedundantAssignment
            rM = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Console.WriteLine("Memory Size:");
            Console.WriteLine("  Raw: {0:#,##0.#}KB", rawMemory / 1024.0);
            Console.WriteLine(
                "  Serialized: {0:#,##0.#}KB ({1:0.00}%)",
                serializeMemory / 1024.0,
                ((float)serializeMemory / rawMemory) * 100);
            Console.WriteLine(
                "  Serialized + Compressed: {0:#,##0.#}KB ({1:0.00}%)",
                compressMemory / 1024.0,
                ((float)compressMemory / rawMemory) * 100);
        }