コード例 #1
0
        public void Run(Program.Options options)
        {
            _runCount = options.RunCount ?? 7;

            Console.WriteLine($"Throughput Test to run => {_perfTestType.FullName}, Runs => {_runCount}");

            _test = (IThroughputTest)Activator.CreateInstance(_perfTestType);
            CheckProcessorsRequirements(_test);

            Console.WriteLine("Starting");
            var context = new ThroughputSessionContext();

            for (var i = 0; i < _runCount; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();

                context.Reset();

                var beforeGen0Count = GC.CollectionCount(0);
                var beforeGen1Count = GC.CollectionCount(1);
                var beforeGen2Count = GC.CollectionCount(2);

                long      totalOperationsInRun = 0;
                Exception exception            = null;
                ThroughputTestSessionResult result;
                try
                {
                    totalOperationsInRun = _test.Run(context);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (exception != null)
                {
                    result = new ThroughputTestSessionResult(exception);
                }
                else
                {
                    var gen0Count = GC.CollectionCount(0) - beforeGen0Count;
                    var gen1Count = GC.CollectionCount(1) - beforeGen1Count;
                    var gen2Count = GC.CollectionCount(2) - beforeGen2Count;

                    result = new ThroughputTestSessionResult(totalOperationsInRun, context.Stopwatch.Elapsed, gen0Count, gen1Count, gen2Count, context);
                }

                Console.WriteLine(result);
                _results.Add(result);
            }
        }
コード例 #2
0
 public ThroughputTestSessionResult(long totalOperationsInRun, TimeSpan duration, int gen0, int gen1, int gen2, ThroughputSessionContext sessionContext)
 {
     TotalOperationsInRun = totalOperationsInRun;
     BatchPercent         = sessionContext.BatchPercent;
     AverageBatchSize     = sessionContext.AverageBatchSize;
     Duration             = duration;
     Gen0 = gen0;
     Gen1 = gen1;
     Gen2 = gen2;
 }