Binarysharp.Benchmark.Components.GcPerformanceOptimizer.LeaveOptimizedSection C# (CSharp) Method

LeaveOptimizedSection() public method

Leaves a section during which the performance of the current process is optimized.
public LeaveOptimizedSection ( ) : void
return void
        public void LeaveOptimizedSection()
        {
            // Flag the section as disabled
            IsSectionActivated = false;

            // Restores the old latency mode of the Garbage Collector.
            GCSettings.LatencyMode = OldGcLatencyMode;
        }

Usage Example

        public void GcLatencyMode_TestValues()
        {
            // Arrange
            var p = new GcPerformanceOptimizer();

            // Act
            var beforeMode = GCSettings.LatencyMode;

            p.EnterOptimizedSection();
            var whileMode = GCSettings.LatencyMode;

            p.LeaveOptimizedSection();
            var afterMode = GCSettings.LatencyMode;

            // Assert
            Assert.AreEqual(afterMode, beforeMode);
            Assert.AreEqual(GCLatencyMode.SustainedLowLatency, whileMode);
        }