Created
November 12, 2017 22:21
-
-
Save kentcb/4cd8a7f302a585c2dc0b1e6efcad3010 to your computer and use it in GitHub Desktop.
Method Group Performance Test
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
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