-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added benchmark to illustrate potential memory leak with StandardOutW…
…riter eliminated allocations inside StandardOutWriter
- Loading branch information
1 parent
30ecf5f
commit 5e9db63
Showing
5 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/core/Akka.Tests.Performance/Util/StandardOutWriterMemoryBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Akka.Util; | ||
using NBench; | ||
using NBench.PerformanceCounters; | ||
|
||
namespace Akka.Tests.Performance.Util | ||
{ | ||
/// <summary> | ||
/// Testing to see if the use of delegates inside <see cref="StandardOutWriter"/> | ||
/// results in allocations. | ||
/// </summary> | ||
public class StandardOutWriterMemoryBenchmark | ||
{ | ||
private Counter _consoleWriteThroughputCounter; | ||
private const string ConsoleWriteThroughputCounterName = "StandardOutWrites"; | ||
private const string InputStr = "W"; // want to avoid string allocations for this spec | ||
|
||
[PerfSetup] | ||
public void SetUp(BenchmarkContext context) | ||
{ | ||
_consoleWriteThroughputCounter = context.GetCounter(ConsoleWriteThroughputCounterName); | ||
} | ||
|
||
[PerfBenchmark(Description = "Testing to see if the design of the StandardOutWriter produces allocations", | ||
RunMode = RunMode.Throughput, | ||
NumberOfIterations = 13, TestMode = TestMode.Measurement, RunTimeMilliseconds = 1000)] | ||
[CounterMeasurement(ConsoleWriteThroughputCounterName)] | ||
[MemoryAssertion(MemoryMetric.TotalBytesAllocated, MustBe.LessThan, ByteConstants.SixtyFourKb)] | ||
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)] | ||
[PerformanceCounterMeasurement(".NET CLR Memory", "# of Pinned Objects", InstanceName = NBenchPerformanceCounterConstants.CurrentProcessName, UnitName = "objects")] | ||
[PerformanceCounterMeasurement(".NET CLR Memory", "# Bytes in all Heaps", InstanceName = NBenchPerformanceCounterConstants.CurrentProcessName, UnitName = "bytes")] | ||
[PerformanceCounterMeasurement(".NET CLR Memory", "# GC Handles", InstanceName = NBenchPerformanceCounterConstants.CurrentProcessName, UnitName = "handles")] | ||
public void StressTestStandardOutWriter(BenchmarkContext context) | ||
{ | ||
StandardOutWriter.WriteLine(InputStr, ConsoleColor.Black, ConsoleColor.DarkGreen); | ||
_consoleWriteThroughputCounter.Increment(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NBench" version="0.2.1" targetFramework="net45" /> | ||
<package id="NBench.PerformanceCounters" version="0.2.1" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters