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

EnterOptimizedSection() public method

Enters a section during which the performance of the current process is optimized.
Why use SustainedLowLatency instead of LowLatency: http://www.infoq.com/news/2012/03/Net-403.
public EnterOptimizedSection ( ) : void
return void
        public void EnterOptimizedSection()
        {
            // Flag the section as activated
            IsSectionActivated = true;

            // Store the current latency mode of the Garbage Collector
            OldGcLatencyMode = GCSettings.LatencyMode;

            // Set the latency to the lowest value
            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
        }

Usage Example

コード例 #1
0
        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);
        }