Created
February 18, 2020 09:03
-
-
Save sonnemaf/75871a74c952c1c50bc132b877b9d4fa to your computer and use it in GitHub Desktop.
Source used in a tweet
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using System; | |
using System.Linq; | |
public class Program { | |
static void Main(string[] args) => BenchmarkRunner.Run(typeof(Program)); | |
private Func<int, int> _delegateToStaticMethod; | |
private Func<int, int> _delegateToInstanceMethod; | |
private static int StaticTarget(int x) => x + 1; | |
private int InstanceTarget(int x) => x + 1; | |
[GlobalSetup] | |
public void Setup() { | |
_delegateToStaticMethod = StaticTarget; | |
_delegateToInstanceMethod = InstanceTarget; | |
} | |
[Benchmark] | |
public int DelegateToInstanceMethodInt() =>_delegateToInstanceMethod(1); | |
[Benchmark] | |
public int DelegateToStaticMethodInt() => _delegateToStaticMethod(1); | |
[Benchmark] | |
public void DelegateToInstanceMethodVoid() => _delegateToInstanceMethod(1); | |
[Benchmark] | |
public void DelegateToStaticMethodVoid() => _delegateToStaticMethod(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment