Пример #1
0
        public static void Time(SortBase sort, string sortType, int count = 100, int length = 10000)
        {
            long total = 0;

            for (int j = 0; j < count; j++)
            {
                int[]     a     = GetArray(sortType, length);
                Stopwatch watch = Stopwatch.StartNew();
                sort.Sort(a);
                long elapsed = watch.ElapsedMilliseconds;
                total += elapsed;
            }
            string.Format("sort {0} elements need {1} ms in average of {2}", length, total / count, sortType).Dump();
        }
Пример #2
0
        public static void Run(SortBase sort, string sortType)
        {
            int length = 10;

            int[] a = GetArray(sortType, length);
            string.Join(",", a).Dump();
            sort.Sort(a);
            Assert(a).Dump();
            string.Join(",", a).Dump();

            System.Console.WriteLine("compare content : {0}", sort.Statistic.CompareContent);
            System.Console.WriteLine("exchange content : {0}", sort.Statistic.ExchangeContent);
            System.Console.WriteLine("access content : {0}", sort.Statistic.AccessContent);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            string sortType  = "bubble";
            string sortOrder = "random";

            if (args.Length >= 2)
            {
                sortType  = args[0];
                sortOrder = args[1];
            }
            else if (args.Length >= 1)
            {
                sortType = args[0];
            }
            System.Console.WriteLine("{0} sort {1} order", sortType, sortOrder);
            SortBase sort = GetSort(sortType);

            Run(sort, sortOrder);
            //Time(sort, "asc");
            //Time(sort, "desc");
            //Time(sort, "random", 1, 1000000);
        }