Created
December 16, 2019 06:49
-
-
Save smoogipoo/5d3ccacc7cd2c3f475fcf15303b542ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Running; | |
| namespace Benchmarks | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| => BenchmarkRunner.Run<BenchmarkClass>(); | |
| } | |
| [MemoryDiagnoser] | |
| public class BenchmarkClass | |
| { | |
| private NoFinalizer noFinalizer; | |
| private WithFinalizer withFinalizer; | |
| [Benchmark] | |
| public void NoFinalizer() | |
| { | |
| for (int i = 0; i < 1000; i++) | |
| noFinalizer = new NoFinalizer(); | |
| } | |
| [Benchmark] | |
| public void WithFinalizer() | |
| { | |
| for (int i = 0; i < 1000; i++) | |
| withFinalizer = new WithFinalizer(); | |
| } | |
| [IterationCleanup] | |
| public void Cleanup() | |
| { | |
| if (withFinalizer != null) | |
| GC.SuppressFinalize(withFinalizer); | |
| } | |
| } | |
| public class NoFinalizer | |
| { | |
| } | |
| public class WithFinalizer | |
| { | |
| public WithFinalizer() | |
| { | |
| } | |
| ~WithFinalizer() | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment