private void RunStringTests()
        {
            bool significant = PerformancePatterns.RunPerformanceComparison(cMinPerfIterations,
                                                                            "dictionary with string keys", (() =>
            {
                var ndx = _stringKeys[_rng.Next(0, _stringKeys.Count)];
                string desc;
                _dictionary.TryGetValue(ndx, out desc);
            }),
                                                                            "datatable with string keys", (() =>
            {
                var ndx = _stringKeys[_rng.Next(0, _stringKeys.Count)];

                string desc;

                DataRow[] rows = _stringDataTable.Select("codeColumn = '" + ndx + "'");
                if (rows.Length > 0)
                {
                    desc = rows[0]["valueColumn"].ToString();
                }
            }),
                                                                            00.0, TwoSampleHypothesis.FirstValueIsSmallerThanSecond, true);

            Assert.IsTrue(significant);
        }
        private void RunSITests()
        {
            bool significant = PerformancePatterns.RunPerformanceComparison(cMinPerfIterations,
                                                                            "datatable with int keys", (() =>
            {
                var ndx = _intKeys[_rng.Next(0, _intKeys.Count)];
                string desc;

                DataRow[] rows = _intDataTable.Select(String.Format("codeColumn = {0}", ndx));
                if (rows.Length > 0)
                {
                    desc = rows[0]["valueColumn"].ToString();
                }
            }),
                                                                            "datatable with string keys", (() =>
            {
                var ndx = _stringKeys[_rng.Next(0, _stringKeys.Count)];

                string desc;

                DataRow[] rows = _stringDataTable.Select("codeColumn = '" + ndx + "'");
                if (rows.Length > 0)
                {
                    desc = rows[0]["valueColumn"].ToString();
                }
            }),
                                                                            100.0, TwoSampleHypothesis.ValuesAreDifferent, true);

            Assert.IsTrue(significant);
        }
        public void BoxedListVsGenericList()
        {
            bool significant = PerformancePatterns.RunPerformanceComparison(cMinPerfIterations,
                                                                            "List<object>", (() =>
            {
                if (_boxList.Count < (cMinPerfIterations >> 2))
                {
                    _boxList.Add(_rng.Next());
                }
                else
                {
                    int i = _rng.Next(0, _boxList.Count - 1);
                    var r = (int)_boxList[i];
                    _boxList.RemoveAt(i);
                }
            }),
                                                                            "List<int>", (() =>
            {
                if (_noboxList.Count < (cMinPerfIterations >> 2))
                {
                    _noboxList.Add(_rng.Next());
                }
                else
                {
                    int i = _rng.Next(0, _noboxList.Count - 1);
                    int r = _noboxList[i];
                    _noboxList.RemoveAt(i);
                }
            }),
                                                                            0.0, TwoSampleHypothesis.ValuesAreDifferent, true);

            Assert.IsTrue(significant);
        }
        public void CompareManualConcurrencyVsLinq()
        {
            var concurrent = new ConcurrentPrimes();

            concurrent.Init(cMinPrime, cMaxPrime, cDegreeConcurrency);
            var plinqed = new PlinqPrimes();

            plinqed.Init(cMinPrime, cMaxPrime, cDegreeConcurrency);

            bool significant = PerformancePatterns.RunPerformanceComparison(cMinPerfIterations,
                                                                            "concurrent collection", (concurrent.Execute),
                                                                            "plinq", (plinqed.Execute),
                                                                            250.0, TwoSampleHypothesis.FirstValueIsGreaterThanSecond, true);

            Assert.IsTrue(significant);
            Assert.AreEqual(concurrent.Primes.Count, plinqed.Primes.Count);
        }
Beispiel #5
0
        public void CompareWithAndWithoutLookup()
        {
            bool significant = PerformancePatterns.RunPerformanceComparison(cMinPerfIterations,
                                                                            "serial with lookup", (() =>
            {
                _myLookup = _bigList.ToLookup(p => p.PayId, p => p);

                var payids = _myLookup.Select(g => g.Key);

                var myStuff = (from payid in payids
                               select new
                {
                    PayId = payid,
                    coverages =
                        string.Join(",", _myLookup[payid].Select(x => x.Category).Distinct()),
                    total = _myLookup[payid].Select(x => x.PaymentAmount).Sum()
                }).ToList();
            }),
                                                                            "serial without lookup", (() =>
            {
                var payids = (from payment in _bigList
                              select payment.PayId).Distinct();

                var myStuff = (from payid in payids
                               select new
                {
                    PayId = payid,
                    coverages =
                        string.Join(", ",
                                    _bigList.Where(x => x.PayId == payid)
                                    .Select(x => x.Category)
                                    .Distinct()),
                    total =
                        _bigList.Where(x => x.PayId == payid)
                        .Select(x => x.PaymentAmount)
                        .Sum()
                }).ToList();
            }),
                                                                            0.0, TwoSampleHypothesis.FirstValueIsSmallerThanSecond, true);

            Assert.IsTrue(significant);
        }
        public void LockVsConcurrentQueue()
        {
            bool significant = PerformancePatterns.RunConcurrentPerformanceComparison(cMinPerfIterations,
                                                                                      cDegreeConcurrency,
                                                                                      "Lock{}", (() =>
            {
                lock (_collectionLock)
                {
                    int v = _rng.Next(1, cMinPerfIterations);
                    if (_bigList.Count > (cMinPerfIterations >> 2))
                    {
                        var s = _bigList[v % _bigList.Count];
                        _bigList.RemoveAt(v % _bigList.Count);
                    }
                    else
                    {
                        _bigList.Add(v);
                    }
                }
            }),
                                                                                      "BlockingCollection<int>", (() =>
            {
                int v = _rng.Next(1, cMinPerfIterations);
                if (_concurrentQ.Count > (cMinPerfIterations >> 2))
                {
                    var s = _concurrentQ.Take();
                }
                else
                {
                    _concurrentQ.Add(v);
                }
            }),
                                                                                      0.0, TwoSampleHypothesis.FirstValueIsGreaterThanSecond, true);

            Assert.IsTrue(significant);
        }