Esempio n. 1
0
        public static void Run_CountingSort_D(int seed, int[] values)
        {
            string fileName  = @"mydataarray.dat";
            string fileName2 = @"mydatalist.dat";

            Console.WriteLine("=== ARRAY ===");

            for (int i = 0; i < values.Length; i++)
            {
                MyFileArray myFileArray = new MyFileArray(fileName, values[i], seed);
                using (myFileArray.fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
                {
                    var watch = Stopwatch.StartNew();
                    CountingSort_Array(myFileArray);
                    watch.Stop();
                    string time = watch.Elapsed.ToString();
                    Console.WriteLine("{0,-20}      {1}", values[i], time);
                }
            }
            Console.WriteLine("=== LIST ===");

            for (int i = 0; i < values.Length; i++)
            {
                MyFileList myFileList = new MyFileList(fileName2, values[i], seed);
                using (myFileList.fs = new FileStream(fileName2, FileMode.Open, FileAccess.ReadWrite))
                {
                    var watch = Stopwatch.StartNew();
                    CountingSort_List(myFileList);
                    watch.Stop();
                    string time = watch.Elapsed.ToString();
                    Console.WriteLine("{0,-20}      {1}", values[i], time);
                }
            }
        }
Esempio n. 2
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. 3
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("|---------------------------|");
        }