Previously viewedArticleMarshalbyrefobject will cause performance loss. I believe it myself, so I personally tested it. below isCode:
Test code
Using System;
Using System. diagnostics;
Namespace Leleapplication1 {
Class Program {
Static Void Main ( String [] ARGs) {
Stopwatch watch = New Stopwatch ();
Watch. Start ();
B = New B ();
For ( Int I = 0 ; I < 100000000 ; I ++ ) {
B. Add (3,5);
}
Watch. Stop ();
Console. writeline ( " Time spent by B: " + Watch. elapsedmilliseconds. tostring ());
Watch. Reset ();
Watch. Start ();
A = New A ();
For ( Int I = 0 ; I < 100000000 ; I ++ ) {
A. Add (3,5);
}
Watch. Stop ();
Console. writeline ( " A marshalbyrefobject takes time: " + Watch. elapsedmilliseconds. tostring ());
Watch. Reset ();
// ======================================
Watch. Start ();
A = New A ();
For ( Int I = 0 ; I < 100000000 ; I ++ ) {
A. Add (3,5);
}
Watch. Stop ();
Console. writeline ( " A marshalbyrefobject takes time: " + Watch. elapsedmilliseconds. tostring ());
Watch. Reset ();
Watch. Start ();
B = New B ();
For ( Int I = 0 ; I < 100000000 ; I ++ ) {
B. Add (3,5);
}
Watch. Stop ();
Console. writeline ( " Time spent by B: " + Watch. elapsedmilliseconds. tostring ());
Watch. Reset ();
Console. Read ();
}
}
Class A: financialbyrefobject {
Public Int Add ( Int A, Int B) {
ReturnA+B;
}
}
Class B {
Public Int Add ( Int A, Int B) {
ReturnA+B;
}
}
}
The test result is:
Time spent by B: 55
A required albyrefobject time: 957
A required albyrefobject time: 972
Time spent by B: 56
Conclusion: In such a local environment, the performance is still nearly 17.4 times lost. Of course, this 17 cannot be simply understood as 17 times slower for your application. Here, it only means that the number of calls initiated is 17 times slower.
Note:
Run the testProgramFirst, select release, and then select project property =, build (Compilation) =, advanced =, and debug information to none.
Then select DEBUG =. Or find the EXE and double-click it.