Esempio n. 1
0
        static void Main(string[] args)
        {
            int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;

            // Antras etapas
            int    n = 12;
            string filename;

            filename = @"mydataarray.dat";
            MyFileArray myfilearray = new MyFileArray(filename, n, seed);

            using (myfilearray.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n FILE ARRAY \n");
                myfilearray.Print(n);
                QuickSort(myfilearray, 0, n - 1);
                myfilearray.Print(n);
            }

            filename = @"mydatalist.dat";
            MyFileList myfilelist = new MyFileList(filename, n, seed);

            using (myfilelist.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n FILE LIST \n");
                myfilelist.Print(n);
                QuickSort(myfilelist, 0, n - 1);
                myfilelist.Print(n);
            }

            SpeedTest();
        }
Esempio n. 2
0
        private static void SpeedTest()
        {
            Stopwatch stopWatch = new Stopwatch();

            string filename1 = @"mydataarray.dat";
            string filename2 = @"mydatalist.dat";

            MyFileArray myArray;
            MyFileList  myList;

            int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;

            int[] numbers = { 100, 200, 400, 800, 1600, 3200, 6400 };

            Console.WriteLine("EXTERNAL MEMORY ARRAY QUICK SORT");
            Console.WriteLine("|---------------------------|");
            Console.WriteLine("|  N          |  Run time   |");
            Console.WriteLine("|---------------------------|");
            foreach (int number in numbers)
            {
                //speed test for array
                myArray = new MyFileArray(filename1, number, seed);
                using (myArray.fs = new FileStream(filename1, FileMode.Open, FileAccess.ReadWrite))
                {
                    stopWatch.Start();
                    QuickSort(myArray, 0, number - 1);
                    stopWatch.Stop();
                }

                Console.WriteLine("|  {0,-9}  |  {1,2}:{2,2}:{3,3}  |", number,
                                  stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds, stopWatch.Elapsed.Milliseconds);

                //reseting stop watch
                stopWatch.Reset();
            }
            Console.WriteLine("|---------------------------|\n");

            Console.WriteLine("EXTERNAL MEMORY LIST QUICK SORT");
            Console.WriteLine("|---------------------------|");
            Console.WriteLine("|  N          |  Run time   |");
            Console.WriteLine("|---------------------------|");
            foreach (int number in numbers)
            {
                //speed test for array
                myList = null;
                myList = new MyFileList(filename2, number, seed);
                using (myList.fs = new FileStream(filename2, FileMode.Open, FileAccess.ReadWrite))
                {
                    stopWatch.Start();
                    QuickSort(myList, 0, number - 1);
                    stopWatch.Stop();
                }

                Console.WriteLine("|  {0,-9}  |  {1,2}:{2,2}:{3,3}  |", number,
                                  stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds, stopWatch.Elapsed.Milliseconds);

                //reseting stop watch
                stopWatch.Reset();
            }
            Console.WriteLine("|---------------------------|");
        }