Skip to content

Instantly share code, notes, and snippets.

@smoogipoo
Created December 16, 2019 06:49
Show Gist options
  • Select an option

  • Save smoogipoo/5d3ccacc7cd2c3f475fcf15303b542ac to your computer and use it in GitHub Desktop.

Select an option

Save smoogipoo/5d3ccacc7cd2c3f475fcf15303b542ac to your computer and use it in GitHub Desktop.
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