Go with the flow with no .net core learning system, only know .net core cross-platform support, not the other way on the point of speaking out one or two, a point of listening to the teacher talked about today, recorded
Test points: the .net core / .net framework different platform interfaces, abstract classes, and each class corresponding implementation class cycle call, the maximum operating efficiency which is which platform?
Two new console program, .net core (3.1) and .net framework (I used 4.7.2)
The same piece of code, running on different platforms, the following is the code:
. 1 class Program 2 { . 3 static void the Main ( String [] args) . 4 { . 5 . 6 Console.WriteLine ( " test different frames, the abstract class interface Efficiency: Core .NET 3.1 Release: " ); . 7 var T = new new the Test (); . 8 t.PerformanceTest (); . 9 the Console.ReadKey (); 10 } . 11 }
1 namespace CoreConsole 2 { 3 public class Test 4 { 5 public void PerformanceTest() 6 { 7 8 IChild record1 = new IChild(); 9 IBase record2 = record1; 10 11 AbsChild row1 = new AbsChild(); 12 AbsBaseClass row2 = row1; 13 14 Child result1 = new Child(); 15 Result2 = Base RESULT1; 16 . 17 Console.WriteLine ($ " cycle {int.MaxValue} times, to perform an interface, abstract classes, classes and methods which implement the class " ); 18 is . 19 The Stopwatch Stopwatch = new new The Stopwatch (); 20 is 21 is 22 is stopwatch.Restart (); 23 is for ( int I = 0 ; I < int .MaxValue; I ++ ) 24 { 25 record1.Do (); 26 is } 27 Console.WriteLine ($ "Interface implementation class called Time: {stopwatch.ElapsedMilliseconds} ms " ); 28 29 30 stopwatch.Restart (); 31 is for ( int I = 0 ; I < int .MaxValue; I ++ ) 32 { 33 is record2.Do (); 34 is } 35 Console.WriteLine ($ " Interface base class called time: {stopwatch.ElapsedMilliseconds} ms " ); 36 37 [ 38 is 39 stopwatch.Restart (); 40 for ( int I =0 ; I < int .MaxValue; I ++ ) 41 is { 42 is row1.Do (); 43 is } 44 is Console.WriteLine ($ " abstract implementation class called Time: {stopwatch.ElapsedMilliseconds} ms " ); 45 46 is 47 stopwatch.Restart ( ); 48 for ( int I = 0 ; I < int .MaxValue; I ++ ) 49 { 50 row2.Do (); 51 is } 52 is Console.WriteLine ($ " abstract base class called Time: {stopwatch.ElapsedMilliseconds} ms " ); 53 is 54 is 55 56 is stopwatch.Restart (); 57 is for ( int I = 0 ; I < int .MaxValue; I ++ ) 58 { 59 result1.Do (); 60 } 61 is Console.WriteLine ($ " class called time: {stopwatch.ElapsedMilliseconds} ms " ); 62 is 63 is stopwatch.Restart (); 64 for (int I = 0 ; I < int .MaxValue; I ++ ) 65 { 66 result2.Do (); 67 } 68 Console.WriteLine ($ " base class called Time: {stopwatch.ElapsedMilliseconds} ms " ); 69 70 } 71 } 72 73 is public interface of IBase 74 { 75 void the Do (); 76 } 77 78 public class ICHILD: of IBase 79 { 80 public void Do () 81 { 82 83 } 84 } 85 86 public abstract class AbsBaseClass 87 { 88 public abstract void Do (); 89 } 90 91 public class AbsChild: AbsBaseClass 92 { 93 public override void Do () 94 { 95 } 96 } 97 98 public class Base 99 { 100 public virtual void Do() { } 101 } 102 103 public class Child : Base 104 { 105 public override void Do() 106 { 107 108 } 109 } 110 }
FIG running under the effect comparison chart:
The overall test is down .net core> .net framework and about 10 times faster (I think about teachers run a 7-8 times faster)
Who abstract interfaces and high efficiency? I will test the method cycles 10 times,:. Net core in roughly the same, the abstract class> Interface (slightly)
Personal experience: in the choice of interfaces and abstract classes, eventually see big business needs - to use common interfaces (bio: people, fish, dogs), it is characteristic abstract ~ (fish: carp, grass carp, carp)
Beginner, there is something wrong, please correct me -
Finally, who can point out why such a big difference between the two platforms do?