Marshalbyrefobject performance loss

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.