Exemplo n.º 1
0
        private async Task <TimeSpan> QuickSortRoutine(ParallelQuickSorter <int> qs)
        {
            var arr = SortHelper.GenerateArray(10_000_000);

            var start = DateTime.Now.TimeOfDay;

            //await qs.QuickSortAsync(arr);
            await Task.Run(() => qs.QuickSort(arr));

            var finish = DateTime.Now.TimeOfDay;

            lock (_lockObject)
                PrintResult(finish - start, arr.CheckSort(), "Parallel QuickSort", arr.Length);

            return(finish - start);
        }
Exemplo n.º 2
0
        public async Task ParallelQuickSort()
        {
            var qs = new ParallelQuickSorter <int>();

            var tasks = new Task <TimeSpan> [5];

            for (int j = 0; j < tasks.Length; j++)
            {
                tasks[j] = Task.Run(() => QuickSortRoutine(qs));
            }

            await Task.WhenAll(tasks);

            Yellow.WriteLine(
                $"Average time is {new TimeSpan(Convert.ToInt64(tasks.Average(task => task.Result.Ticks)))}\n");
        }
Exemplo n.º 3
0
        public async Task TestParallelQuickSort()
        {
            var qs = new ParallelQuickSorter <int>();

            for (int i = 70; i <= 100; i += 10)
            {
                Console.WriteLine($"InsertionBound = {i}");

                var tasks = new Task <TimeSpan> [5];

                for (int j = 0; j < 5; j++)
                {
                    tasks[j] = Task.Run(() => QuickSortRoutine(qs));
                }

                await Task.WhenAll(tasks);

                Yellow.WriteLine(
                    $"Average time is {new TimeSpan(Convert.ToInt64(tasks.Average(task => task.Result.Ticks)))}\n");
            }
        }