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);
            }
        }
Esempio n. 2
0
        public void Run()
        {
            _test = (IThroughputTest)Activator.CreateInstance(_perfTestType);
            CheckProcessorsRequirements(_test);

            Console.WriteLine("Starting throughput tests");
            var stopwatch = new Stopwatch();

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

                stopwatch.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(stopwatch);
                }
                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, stopwatch.Elapsed, gen0Count, gen1Count, gen2Count);
                }

                Console.WriteLine(result);
                _results.Add(result);
            }
        }
        public void Run()
        {
            _test = (IThroughputTest)Activator.CreateInstance(_perfTestType);
            CheckProcessorsRequirements(_test);

            Console.WriteLine("Starting throughput tests");
            var stopwatch = new Stopwatch();
            for (var i = 0; i < Runs; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();

                stopwatch.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(stopwatch);
                }
                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, stopwatch.Elapsed, gen0Count, gen1Count, gen2Count);
                }

                Console.WriteLine(result);
                _results.Add(result);
            }
        }