| 6 | | object obj1 = ExtensionFunction<Test>.Create(); |
|---|
| 7 | | object obj2 = ExtensionFunction<Test>.Create("Created with a single string parameter"); |
|---|
| 8 | | object obj3 = ExtensionFunction<Test>.Create("Created with two", "string parameters"); |
|---|
| 9 | | Console.WriteLine("Test.GetOutput(\"test1\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj1, "GetOutput", "test1")); |
|---|
| 10 | | Console.WriteLine("Test.GetOutput(\"test2\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj2, "GetOutput", "test2")); |
|---|
| 11 | | Console.WriteLine("Test.GetOutput(\"test3\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj3, "GetOutput", "test3")); |
|---|
| | 12 | Stopwatch stopwatch = new Stopwatch(); |
|---|
| | 13 | int count = 100; |
|---|
| | 14 | TestDirect(count, stopwatch); |
|---|
| | 15 | TestGenerics(count, stopwatch); |
|---|
| | 16 | Console.WriteLine("Completed direct test in:\t {0}ms", directEllapsedTime); |
|---|
| | 17 | Console.WriteLine("Completed generics test in:\t {0}ms", genericsEllapsedTime); |
|---|
| | 18 | } |
|---|
| | 19 | |
|---|
| | 20 | public static void TestDirect(int count, Stopwatch stopwatch){ |
|---|
| | 21 | Console.WriteLine("Starting direct object creation and method invocation test."); |
|---|
| | 22 | stopwatch.Start(); |
|---|
| | 23 | for (int i = 0; i <= count; i++) { |
|---|
| | 24 | Test obj1 = new Test(); |
|---|
| | 25 | Test obj2 = new Test("Created with a single string parameter"); |
|---|
| | 26 | Test obj3 = new Test("Created with two", "string parameters"); |
|---|
| | 27 | Console.WriteLine("Test.GetOutput(\"test1\") returned: {0}", obj1.GetOutput("test1")); |
|---|
| | 28 | Console.WriteLine("Test.GetOutput(\"test2\") returned: {0}", obj2.GetOutput("test2")); |
|---|
| | 29 | Console.WriteLine("Test.GetOutput(\"test3\") returned: {0}", obj3.GetOutput("test3")); |
|---|
| | 30 | } |
|---|
| | 31 | stopwatch.Stop(); |
|---|
| | 32 | directEllapsedTime = stopwatch.ElapsedMilliseconds; |
|---|
| | 33 | Console.WriteLine("Complete!"); |
|---|
| | 34 | stopwatch.Reset(); |
|---|
| | 35 | } |
|---|
| | 36 | |
|---|
| | 37 | public static void TestGenerics(int count, Stopwatch stopwatch) { |
|---|
| | 38 | Console.WriteLine("Starting generic object creation and method invocation test."); |
|---|
| | 39 | stopwatch.Start(); |
|---|
| | 40 | for (int i = 0; i <= count; i++) { |
|---|
| | 41 | object obj1 = ExtensionFunction<Test>.Create(); |
|---|
| | 42 | object obj2 = ExtensionFunction<Test>.Create("Created with a single string parameter"); |
|---|
| | 43 | object obj3 = ExtensionFunction<Test>.Create("Created with two", "string parameters"); |
|---|
| | 44 | Console.WriteLine("Test.GetOutput(\"test1\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj1, "GetOutput", "test1")); |
|---|
| | 45 | Console.WriteLine("Test.GetOutput(\"test2\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj2, "GetOutput", "test2")); |
|---|
| | 46 | Console.WriteLine("Test.GetOutput(\"test3\") returned: {0}", ExtensionFunction<Test>.Invoke<String>(obj3, "GetOutput", "test3")); |
|---|
| | 47 | } |
|---|
| | 48 | stopwatch.Stop(); |
|---|
| | 49 | genericsEllapsedTime = stopwatch.ElapsedMilliseconds; |
|---|
| | 50 | Console.WriteLine("Complete!"); |
|---|
| | 51 | stopwatch.Reset(); |
|---|