["$ interface..E$ ","A&ABXBXCP}Z(.C","Interface Performance."," Are interface calls faster than virtual ones? If we use an interface, we implement that interface as a contract. If we use a base class, we declare virtual methods and then implement those methods on derived types. ","Virtual ","virtual","Example."," This example program is a benchmark harness. It first declares a type that implements a method from an interface. It also declares a type that implements a method matching a base class virtual method. ","The .NET 3.5 Framework was used for this benchmark. The two patterns are occasionally interchangeable in software projects.","C# program that tests performance","\n\nusing System;\nusing System.Diagnostics;\n\ninterface IInterfaceExample\n{\n void Y();\n}\n\nclass ImplementsInterface : IInterfaceExample\n{\n public void Y()\n {\n }\n}\n\nclass BaseExample\n{\n public virtual void Y()\n {\n }\n}\n\nclass DerivesBase : BaseExample\n{\n public override void Y()\n {\n }\n}\n\nclass Program\n{\n const int _max = 100000000;\n static void Main()\n {\n IInterfaceExample interface1 = new ImplementsInterface();\n BaseExample base1 = new DerivesBase();\n interface1.Y();\n base1.Y();\n\n var s1 = Stopwatch.StartNew();\n for (int i = 0; i < _max; i++)\n {\n interface1.Y();\n }\n s1.Stop();\n var s2 = Stopwatch.StartNew();\n for (int i = 0; i < _max; i++)\n {\n base1.Y();\n }\n s2.Stop();\n Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000 * 1000) /\n _max).ToString(\"0.00 ns\"));\n Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000 * 1000) /\n _max).ToString(\"0.00 ns\"));\n Console.Read();\n }\n}\n\n","\n\n3.21 ns\n2.24 ns","You can see"," that this test shows that an interface method invocation is somewhat slower than a virtual method call. The interface call takes over 3 nanoseconds, while the virtual method call takes over 2 nanoseconds.","Therefore,"," we surmise that replacing an interface-based type layout with a class-based, virtual method type layout would likely improve performance. Interface calls are not faster.","Summary."," Interfaces have some level of performance impairment. Both interface method invocations and virtual method calls inject another level of indirection. But the runtime is able to more quickly cope with that added by virtual methods. ","Where possible, changing interfaces to base classes with virtual methods can improve performance of method invocations."]

%iVBORw0KG;)NSUhEUg?AMg?ABJCAM?ABPapnR)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