Disruptor.PerfTests.LatencyTestSession.Run C# (CSharp) Method

Run() public method

public Run ( ) : void
return void
        public void Run()
        {
            _test = (ILatencyTest)Activator.CreateInstance(_perfTestType);
            CheckProcessorsRequirements(_test);

            Console.WriteLine("Starting latency tests");
            var stopwatch = new Stopwatch();
            var histogram = new LongHistogram(10000000000L, 4);
            for (var i = 0; i < Runs; i++)
            {
                stopwatch.Reset();
                histogram.Reset();
                GC.Collect();
                GC.WaitForPendingFinalizers();

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

                Exception exception = null;
                LatencyTestSessionResult result = null;
                try
                {
                    _test.Run(stopwatch, histogram);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

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

                    result = new LatencyTestSessionResult(histogram, stopwatch.Elapsed, gen0Count, gen1Count, gen2Count);
                }

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

Usage Example

Beispiel #1
0
        private static void RunTestForType(Type perfTestType, bool shouldOpen)
        {
            var isThroughputTest = typeof(IThroughputTest).IsAssignableFrom(perfTestType);
            var isLatencyTest    = typeof(ILatencyTest).IsAssignableFrom(perfTestType);

            var typeName = perfTestType.Name;

            if (!isThroughputTest && !isLatencyTest)
            {
                Console.WriteLine($"*** ERROR *** Unable to determine the runner to use for this type ({typeName})");
                return;
            }

            //Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;

            if (isThroughputTest)
            {
                var session = new ThroughputTestSession(perfTestType);
                session.Run();
                session.GenerateAndOpenReport(shouldOpen);
            }

            if (isLatencyTest)
            {
                var session = new LatencyTestSession(perfTestType);
                session.Run();
                session.GenerateAndOpenReport(shouldOpen);
            }
        }
All Usage Examples Of Disruptor.PerfTests.LatencyTestSession::Run