blob: 5397915181ac445bd4b2abce9ff08ea5c3eb6974 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
using System;
namespace Slow
{
public interface ITest
{
void DoNothing<T>()
where T : class;
}
public class Test : ITest
{
public void DoNothing<T>()
where T : class
{
T x = null;
}
}
class Program
{
public static void Main(string[] args)
{
const int iterations = 10000;
Test test = new Test ();
DateTime start = DateTime.Now;
Console.Write ("Calling Test.DoNothing<Program>() on an object reference... ");
for (int i = 0; i < iterations; ++i)
{
test.DoNothing<Program> ();
}
DateTime end = DateTime.Now;
TimeSpan duration = end - start;
Console.WriteLine ("Took " + duration.TotalMilliseconds + " ms.");
ITest testInterface = test;
start = DateTime.Now;
Console.Write ("Calling Test.DoNothing<Program>() on an interface reference... ");
for (int i = 0; i < iterations; ++i)
{
testInterface.DoNothing<Program> ();
}
end = DateTime.Now;
duration = end - start;
Console.WriteLine ("Took " + duration.TotalMilliseconds + " ms.");
}
}
}
|