Beispiel #1
0
        public void SimpleBenchmark()
        {
            // The list contains 4 items so that the DenseList doesn't need a heap allocation
            // You can test the heap allocated backing store with 5 items, it ends up being somewhat slower
            var dense = new DenseList <decimal> {
                1, 2, 3, 4
            };
            var list = new List <decimal> {
                1, 2, 3, 4
            };
            // for int64 try something like 32
            const int count = 1024000 * 10;

            var started1 = Stopwatch.GetTimestamp();

            unchecked {
                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < dense.Count; j++)
                    {
                        dense[j]++;
                    }
                }
            }
            var ended1 = Stopwatch.GetTimestamp();

            for (int i = 0; i < 4; i++)
            {
                dense[i] = i + 1;
            }

            var started2 = Stopwatch.GetTimestamp();

            unchecked {
                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < dense.Count; j++)
                    {
                        ref var item = ref dense.Item(j);
                        item++;
                    }
                }
            }