Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void VowelCount_TestCount2Proc_Equal()
        {
            string s = "текст для проверки количества гласных";

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

            Assert.Equal(11, checkCount);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void VowelCount_TestCountAllProc_Equal()
        {
            string s =
                $"текст для проверки количества гласных текст для проверки " +
                $"количества гласных текст для проверки количества гласных текст для проверки " +
                $"количества гласных текст для проверки количества гласных текст для проверки количества гласных";

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

            Assert.Equal(66, checkCount);
        }