using System;
using System.Diagnostics;
namespace PruebaRendimientoAbstractInterface
{
interface IInterfaceExample
{
void Y();
}
class ImplementsInterface : IInterfaceExample
{
public void Y()
{
}
}
class BaseExample
{
public virtual void Y()
{
}
}
class DerivesBase : BaseExample
{
public override void Y()
{
}
}
class Program
{
const int _max = 100000000;
static void Main()
{
IInterfaceExample interface1 = new ImplementsInterface();
BaseExample base1 = new DerivesBase();
interface1.Y();
base1.Y();
var s1 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
interface1.Y();
}
s1.Stop();
var s2 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
base1.Y();
}
s2.Stop();
Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000 * 1000) /
_max).ToString("0.00 ns"));
Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000 * 1000) /
_max).ToString("0.00 ns"));
Console.Read();
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uRGlhZ25vc3RpY3M7CgpuYW1lc3BhY2UgUHJ1ZWJhUmVuZGltaWVudG9BYnN0cmFjdEludGVyZmFjZQp7CglpbnRlcmZhY2UgSUludGVyZmFjZUV4YW1wbGUKCXsKCQl2b2lkIFkoKTsKCX0KCgljbGFzcyBJbXBsZW1lbnRzSW50ZXJmYWNlIDogSUludGVyZmFjZUV4YW1wbGUKCXsKCQlwdWJsaWMgdm9pZCBZKCkKCQl7CgkJfQoJfQoKCWNsYXNzIEJhc2VFeGFtcGxlCgl7CgkJcHVibGljIHZpcnR1YWwgdm9pZCBZKCkKCQl7CgkJfQoJfQoKCWNsYXNzIERlcml2ZXNCYXNlIDogQmFzZUV4YW1wbGUKCXsKCQlwdWJsaWMgb3ZlcnJpZGUgdm9pZCBZKCkKCQl7CgkJfQoJfQoKCWNsYXNzIFByb2dyYW0KCXsKCQljb25zdCBpbnQgX21heCA9IDEwMDAwMDAwMDsKCQlzdGF0aWMgdm9pZCBNYWluKCkKCQl7CgkJSUludGVyZmF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