Skip to content

Instantly share code, notes, and snippets.

@kentcb
Created November 12, 2017 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcb/4cd8a7f302a585c2dc0b1e6efcad3010 to your computer and use it in GitHub Desktop.
Save kentcb/4cd8a7f302a585c2dc0b1e6efcad3010 to your computer and use it in GitHub Desktop.
Method Group Performance Test
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
namespace BenchmarkDotNetHarness
{
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<PerformanceTests>();
Console.WriteLine(summary.ToString());
}
}
[MemoryDiagnoser]
[SimpleJob(RunStrategy.Monitoring, launchCount: 2, warmupCount: 2, targetCount: 5, invocationCount: 10000000)]
public class PerformanceTests
{
private int GetStringLength(string s) => s.Length;
[Benchmark(Baseline = true)]
public object CreateLambdaFromMethodGroup()
{
Func<string,int> f = this.GetStringLength;
return f;
}
[Benchmark]
public object CreateLambdaWithoutMethodGroup()
{
Func<string, int> f = i => this.GetStringLength(i);
return f;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment