Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2020 09:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Source used in a tweet
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;
public void Setup() {
_delegateToStaticMethod = StaticTarget;
_delegateToInstanceMethod = InstanceTarget;
public int DelegateToInstanceMethodInt() =>_delegateToInstanceMethod(1);
public int DelegateToStaticMethodInt() => _delegateToStaticMethod(1);
public void DelegateToInstanceMethodVoid() => _delegateToInstanceMethod(1);
public void DelegateToStaticMethodVoid() => _delegateToStaticMethod(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment