private void StartCalculate(CharFinder finder, Dictionary <int, Stopwatch> stopwatchers, int arrLength)
        {
            finder.ResetValue();

            string[] strToCalculate = new string[arrLength];
            for (int i = 0; i < arrLength; i++)
            {
                strToCalculate[i] = finder.strArr[i];
            }

            Stopwatch   stopwatch = new Stopwatch();
            List <Task> tasks     = new List <Task>();

            foreach (var s in strToCalculate)
            {
                tasks.Add(new Task(() => finder.GetCharCount(s)));
            }

            stopwatch.Start();
            foreach (var t in tasks)
            {
                t.Start();
            }

            Task.WaitAll(tasks.ToArray());
            stopwatch.Stop();
            stopwatchers.Add(arrLength, stopwatch);
        }
Esempio n. 2
0
        private async Task StartCalculate(CharFinder finder, Dictionary <int, Stopwatch> stopwatchers, int arrLength)
        {
            finder.ResetValue();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < arrLength; i++)
            {
                await finder.GetCharCountAsync(finder.strArr[i]);
            }
            stopwatch.Stop();
            stopwatchers.Add(arrLength, stopwatch);
        }
        private void StartCalculate(CharFinder finder, Dictionary <int, Stopwatch> stopwatchers, int arrLength)
        {
            Stopwatch stopwatch = new Stopwatch();

            finder.ResetValue();

            stopwatch.Start();
            for (int j = 0; j < arrLength; j++)
            {
                new Thread(finder.GetCharCount).Start(finder.strArr[j]);
            }
            stopwatch.Stop();
            stopwatchers.Add(arrLength, stopwatch);
        }
Esempio n. 4
0
        private void StartCalculate(CharFinder finder, Dictionary <int, Stopwatch> stopWatchers, int arrLength)
        {
            finder.ResetValue();

            string[] strToCalculate = new string[arrLength];
            for (int i = 0; i < arrLength; i++)
            {
                strToCalculate[i] = finder.strArr[i];
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Parallel.ForEach <object>(strToCalculate,
                                      finder.GetCharCount);
            stopwatch.Stop();
            stopWatchers.Add(arrLength, stopwatch);
        }