Пример #1
0
        public static int BestTaskCount(int arrayCount, int minTaskCount, int maxTaskCount)
        {
            int[] buffer = Utils.GenerateIntArray(arrayCount, 15);

            long elapsed       = 0;
            long minElapsed    = long.MaxValue;
            int  bestTaskCount = -1;

            for (int i = minTaskCount; i <= maxTaskCount; i++)
            {
                Stopwatch watch = Stopwatch.StartNew();
                //-------------------------
                int s = ThreadArray.Sum(buffer, i);
                //-------------------------
                watch.Stop();
                elapsed = watch.ElapsedMilliseconds;
                Console.WriteLine($"TaskCount = {i}: Sum of int[{arrayCount}] = {s}, elapsed time is {elapsed} ms.");
                if (elapsed < minElapsed)
                {
                    minElapsed    = elapsed;
                    bestTaskCount = i;
                }
            }
            return(bestTaskCount);
        }
        public void Sum_CompareThreadAndUsualSumOnAllProc_Equal()
        {
            int[] arr       = Utils.GenerateIntArray(100000, 29);
            int   sampleSum = ThreadArray.Sum(arr, 0, arr.Length);
            int   testedSum = ThreadArray.Sum(arr, Environment.ProcessorCount);

            Assert.Equal(sampleSum, testedSum);
        }
        public void VowelCount_TestCount2Proc_Equal()
        {
            string s = "текст для проверки количества гласных";

            int checkCount = ThreadArray.VowelsCount(s, 2);

            Assert.Equal(11, checkCount);
        }
        public void Sum_CompareThreadAndUsualSumOn3Proc_Equal()
        {
            int[] arr       = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int   sampleSum = ThreadArray.Sum(arr, 0, arr.Length);
            int   testedsum = ThreadArray.Sum(arr, 3);

            Assert.Equal(sampleSum, testedsum);
        }
        public void VowelCount_TestCountAllProc_Equal()
        {
            string s =
                $"текст для проверки количества гласных текст для проверки " +
                $"количества гласных текст для проверки количества гласных текст для проверки " +
                $"количества гласных текст для проверки количества гласных текст для проверки количества гласных";

            int checkCount = ThreadArray.VowelsCount(s, Environment.ProcessorCount);

            Assert.Equal(66, checkCount);
        }