Exemplo n.º 1
0
        public void PLinqWork_CompareTimeOfDifferentAmountOfThreadsWorking_SecondTimeIsGreater()
        {
            ThreadsFunction.Strings       = new List <String>();
            ThreadsFunction.SortedStrings = new ConcurrentDictionary <string, int>();

            ThreadsFunction.GenerateStringsList(200);

            ThreadsFunction.StrPortion = ThreadsFunction.Strings.Count / 5 + 1;

            //act
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            ThreadsFunction.PLinqWork(5);
            watch.Stop();
            var elapsedMs1 = watch.ElapsedMilliseconds;

            ThreadsFunction.SortedStrings.Clear();
            ThreadsFunction.StrPortion = ThreadsFunction.Strings.Count / 200 + 1;

            watch.Start();
            ThreadsFunction.PLinqWork(200);
            watch.Stop();
            var elapsedMs2 = watch.ElapsedMilliseconds;

            //assert
            Assert.Less(elapsedMs1, elapsedMs2);
        }
Exemplo n.º 2
0
        public void PLinqWork_InputFiveStringsWithThreeSame_DictionarySizeEquals2()
        {
            ThreadsFunction.Strings       = new List <String>();
            ThreadsFunction.SortedStrings = new ConcurrentDictionary <string, int>();
            ThreadsFunction.StrPortion    = 2;

            ThreadsFunction.Strings.Add("Moon");
            ThreadsFunction.Strings.Add("Sun");
            ThreadsFunction.Strings.Add("Sun");
            ThreadsFunction.Strings.Add("Moon");
            ThreadsFunction.Strings.Add("Moon");

            //act
            ThreadsFunction.PLinqWork(3);

            //assert
            Assert.AreEqual(ThreadsFunction.SortedStrings.Count, 2);
        }