Пример #1
0
        private void TestCachePerfHelper(DistributorCache cache, List <InnerData> obj, int count, ref long min,
                                         ref long max, ref float avg)
        {
            var sp = new Stopwatch();

            min = int.MaxValue;
            max = 0;
            avg = 0;
            for (int i = 0; i < count; i++)
            {
                cache.AddToCache(obj[i].Transaction.EventHash, obj[i].Transaction);
            }

            for (int i = 0; i < count; i++)
            {
                sp.Start();
                cache.Update(obj[i].Transaction.EventHash, obj[i].Transaction);
                sp.Stop();
                long mls = sp.ElapsedMilliseconds;
                avg += mls;

                if (min > mls)
                {
                    min = mls;
                }
                if (max < mls)
                {
                    max = mls;
                }
                sp.Reset();
            }
            avg = avg / count;
        }
Пример #2
0
        public void CachePerformance()
        {
            var ts1   = TimeSpan.FromMilliseconds(400);
            var ts2   = TimeSpan.FromSeconds(1000);
            var cache = new DistributorCache(ts1, ts2);
            var max   = new List <long>();
            var min   = new List <long>();
            var avg   = new List <float>();
            var obj   = new List <InnerData>();

            cache.Start();
            const int count = 10000;

            var calc = new StoredDataHashCalculator();

            for (int i = 0; i < count; i++)
            {
                obj.Add(TestHelper.CreateEvent(calc, i + 1));
            }

            long  v1 = 0, v2 = 0;
            float v3 = 0;

            TestCachePerfHelper(cache, obj, 100, ref v1, ref v2, ref v3);
            cache.Dispose();
            min.Add(v1);
            max.Add(v2);
            avg.Add(v3);

            cache = new DistributorCache(ts1, ts2);
            cache.Start();
            TestCachePerfHelper(cache, obj, 1000, ref v1, ref v2, ref v3);
            cache.Dispose();
            min.Add(v1);
            max.Add(v2);
            avg.Add(v3);

            cache = new DistributorCache(ts1, ts2);
            cache.Start();
            TestCachePerfHelper(cache, obj, 10000, ref v1, ref v2, ref v3);
            cache.Dispose();
            min.Add(v1);
            max.Add(v2);
            avg.Add(v3);
        }