using System.Diagnostics;
public interface IMyInterface
public class Implementation : IMyInterface
private readonly Random _random = new Random();
public int TotalValue { get; private set; }
TotalValue += _random.Next(1, 11);
private const int Iterations = 50000000;
private static void DoThing(IMyInterface thing)
private static void DoOtherThing<T>(T thing) where T : IMyInterface
private static int Test(Action testAction)
var swatch = new Stopwatch();
for (var i = 0; i < Iterations; i++)
return (int)swatch.Elapsed.TotalMilliseconds;
public static void Main()
var thingOne = new Implementation();
var resultOne = Test(() => DoThing(thingOne));
Console.WriteLine("Typed parameter test took: " + resultOne + "ms");
var thingTwo = new Implementation();
var resultTwo = Test(() => DoOtherThing(thingTwo));
Console.WriteLine("Generic parameter test took: " + resultTwo + "ms");
var winner = resultOne > resultTwo ? "generic parameter" : "typed parameter";
Console.WriteLine("The winner is " + winner);