コード例 #1
0
    public static void Main()
    {
        Unidimensional   uni   = new Unidimensional();
        Multidimensional multi = new Multidimensional();
        Jagged           jag   = new Jagged();

        uni.Processar();
        multi.Processar();
        jag.Processar();
    }
コード例 #2
0
        public void TestEnumeration32()
        {
            var expected = new[]
            {
                new[] { 0, 0 },
                new[] { 0, 1 },
                new[] { 1, 0 },
                new[] { 1, 1 },
                new[] { 2, 0 },
                new[] { 2, 1 },
            };
            var actual = Multidimensional.EnumerateIndexes(new[] { 3, 2 }).ToArray();

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void Run()
        {
            PrintCPUInfo();

            const int dimensionSize  = 256; // the dimension size for arrays.
            const int iterationCount = 10;  // how many iterations should we go for?

            // load the tests
            var multidimensionalArray = new Multidimensional(dimensionSize);
            var jaggedArray           = new Jagged(dimensionSize);
            var flattenArray          = new Flatten(dimensionSize);

            // timespans for measuring averages
            var timeSpanMultiSequentals   = new TimeSpan[iterationCount];
            var timeSpanJaggedSeqentals   = new TimeSpan[iterationCount];
            var timeSpanFlattenSequentals = new TimeSpan[iterationCount];
            var timeSpanMultiRandoms      = new TimeSpan[iterationCount];
            var timeSpanJaggedRandoms     = new TimeSpan[iterationCount];
            var timeSpanFlattenRandoms    = new TimeSpan[iterationCount];

            Console.WriteLine("Array size: {0}*{0}*{0}", dimensionSize);

            // test the sequental access
            Console.WriteLine("________________________________________________________________________________");
            Console.WriteLine("Itr.\tMulti.\tJagged\tFlatten\t(Sequental)");
            Console.WriteLine("________________________________________________________________________________");

            for (int i = 0; i < iterationCount; i++)
            {
                Console.Write("#{0}\t", i + 1);

                TimeSpan multidimensionalSequental = multidimensionalArray.AccessSequental();
                timeSpanMultiSequentals[i] = multidimensionalSequental;
                Console.Write(String.Format("{0:00}.{1:000}s\t", multidimensionalSequental.Seconds, multidimensionalSequental.Milliseconds));

                TimeSpan jaggedSequental = jaggedArray.AccessSequental();
                timeSpanJaggedSeqentals[i] = jaggedSequental;
                Console.Write(String.Format("{0:00}.{1:000}s\t", jaggedSequental.Seconds, jaggedSequental.Milliseconds));

                TimeSpan flattenSequental = flattenArray.AccessSequental();
                timeSpanFlattenSequentals[i] = flattenSequental;
                Console.Write(String.Format("{0:00}.{1:000}s\t", flattenSequental.Seconds, flattenSequental.Milliseconds));

                Console.WriteLine();
            }

            // averages for sequentals
            Console.Write("~Avg\t");

            TimeSpan multidimensionalSequentalAvg = CalculateAverageTimeSpan(timeSpanMultiSequentals);

            Console.Write(String.Format("{0:00}.{1:000}s\t", multidimensionalSequentalAvg.Seconds, multidimensionalSequentalAvg.Milliseconds));

            TimeSpan timeSpanJaggedSeqentalsAvg = CalculateAverageTimeSpan(timeSpanJaggedSeqentals);

            Console.Write(String.Format("{0:00}.{1:000}s\t", timeSpanJaggedSeqentalsAvg.Seconds, timeSpanJaggedSeqentalsAvg.Milliseconds));

            TimeSpan timeSpanFlattenSequentalsAvg = CalculateAverageTimeSpan(timeSpanFlattenSequentals);

            Console.Write(String.Format("{0:00}.{1:000}s\t", timeSpanFlattenSequentalsAvg.Seconds, timeSpanFlattenSequentalsAvg.Milliseconds));

            // test the random access

            Console.WriteLine("\n________________________________________________________________________________");
            Console.WriteLine("Itr.\tMulti.\tJagged\tFlatten\t(Random)");
            Console.WriteLine("________________________________________________________________________________");

            for (int i = 0; i < iterationCount; i++)
            {
                Console.Write("#{0}\t", i + 1);

                TimeSpan multidimensionalRandom = multidimensionalArray.AccessRandom();
                timeSpanMultiRandoms[i] = multidimensionalRandom;
                Console.Write(String.Format("{0:00}.{1:000}s\t", multidimensionalRandom.Seconds, multidimensionalRandom.Milliseconds));

                TimeSpan jaggedRandom = jaggedArray.AccessRandom();
                timeSpanJaggedRandoms[i] = jaggedRandom;
                Console.Write(String.Format("{0:00}.{1:000}s\t", jaggedRandom.Seconds, jaggedRandom.Milliseconds));

                TimeSpan flattenRandom = flattenArray.AccessRandom();
                timeSpanFlattenRandoms[i] = flattenRandom;
                Console.Write(String.Format("{0:00}.{1:000}s\t", flattenRandom.Seconds, flattenRandom.Milliseconds));

                Console.WriteLine();
            }

            // averages for sequentals
            Console.Write("~Avg\t");

            TimeSpan multidimensionalRandomAvg = CalculateAverageTimeSpan(timeSpanMultiRandoms);

            Console.Write(String.Format("{0:00}.{1:000}s\t", multidimensionalRandomAvg.Seconds, multidimensionalRandomAvg.Milliseconds));

            TimeSpan jaggedRandomAvg = CalculateAverageTimeSpan(timeSpanJaggedRandoms);

            Console.Write(String.Format("{0:00}.{1:000}s\t", jaggedRandomAvg.Seconds, jaggedRandomAvg.Milliseconds));

            TimeSpan flattenRandomAvg = CalculateAverageTimeSpan(timeSpanFlattenRandoms);

            Console.Write(String.Format("{0:00}.{1:000}s\t", flattenRandomAvg.Seconds, flattenRandomAvg.Milliseconds));

            Console.ReadLine();
        }