Skip to content

Instantly share code, notes, and snippets.

@kkokosa
Created March 28, 2022 14:21
Show Gist options
  • Save kkokosa/6251cd0753a7b862178110d54c9d8b0c to your computer and use it in GitHub Desktop.
Save kkokosa/6251cd0753a7b862178110d54c9d8b0c to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using System.Text;
BenchmarkRunner.Run<Benchmarks>();
[MemoryDiagnoser]
public class Benchmarks
{
private byte[] data;
private Consumer consumer;
public Benchmarks()
{
data = new byte[128];
consumer = new Consumer();
}
[Benchmark]
public StringBuilder A() => new StringBuilder();
[Benchmark]
public (int, (int, (int, int, int)), string) B() => (1, (1, (1, 1, 1)), "x");
[Benchmark]
public void C() => data.Where(x => x > 0).Select(x => x * x).Consume(consumer);
[Benchmark]
public string D() => new string('x', 64);
}
internal class DataClass
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment