示例#1
0
        private static void Sort(ISortable sortable, IGeneratorItems generatorItems, int amount, FileService fileService)
        {
            fileService.Save(path, sortable.ToString());

            Console.WriteLine("---- Analyze " + amount + " ----" + sortable.ToString());
            TimeWatch timer = new TimeWatch();

            timer.Start();
            List <int> list = generatorItems.GetData(amount);

            Console.WriteLine("Time Loading List: " + timer.GetEllapsedMilliSeconds());

            timer.Restart();
            List <int> listOrderAsc  = new List <int>(list);
            List <int> listOrderDesc = new List <int>(list);

            Console.WriteLine("Time Loading List to Order Asc or Desc:" + timer.GetEllapsedMilliSeconds());

            timer.Restart();
            List <int> orderedList = OrderAsc(sortable, listOrderAsc);
            long       timeAsc     = timer.GetEllapsedMilliSeconds();

            Console.WriteLine("Time Ordering Asc:" + timer.GetEllapsedMilliSeconds());

            timer.Restart();
            List <int> orderedDescList = OrderDesc(sortable, listOrderDesc);
            long       timeDesc        = timer.GetEllapsedMilliSeconds();

            Console.WriteLine("Time Ordering Desc:" + timer.GetEllapsedMilliSeconds());

            fileService.Save(path, Environment.NewLine + $"Amount:{amount},TimeAsc:{timeAsc}, TimeDesc:{timeDesc}");
        }
示例#2
0
        private async Task Sort(ISortable sortable, IGeneratorItems generatorItems, int amount, IProgress <SortingCore.Services.TimeWatchSortable.TimeAndValue> p, CancellationTokenSource cts)
        {
            SortingCore.Services.TimeWatchSortable timeWatchSortable = new SortingCore.Services.TimeWatchSortable();
            timeWatchSortable.SetProgress(p);
            timeWatchSortable.SetSortable(sortable);

            List <int> list = generatorItems.GetData(amount);

            timeWatchSortable.Start();
            await Task.Run(() => sortable.SortAscending(list));
        }