Performance Tips and Tricks in. NET Applications (4

Source: Internet
Author: User

Use Binary Compare for Text
When comparing text, use binary compare instead of text compare. At run time, the overhead is much lighter for binary. Minimize the Use of Format ()
When you can, use toString () instead of format (). In most cases, it will provide you with the functionality you need, with much less overhead. Use Charw
Use charw instead of char. the CLR uses Unicode internally, and char must be translated at run time if it is used. this can result in a substantial performance loss, and specifying that your characters are a full word long (using charw) eliminates this conversion. optimize Assignments
Use exp + = val instead of exp = exp + val. since exp can be arbitrarily complex, this can result in lots of unnecessary work. this forces the JIT to evaluate both copies of exp, and usually times this is not needed. the first statement can be optimized far better than the second, since the JIT can avoid evaluating the exp twice. avoid Unnecessary Indirection
When you use byRef, you pass pointers instead of the actual object. when times this makes sense (side-encryption ting functions, for example), but you don't always need it. passing pointers results in more indirection, which is slower than accessing a value that is on the stack. when you don't need to go through the heap, it is best to avoid it. put Concatenations in One Expression
If you have multiple concatenations on multiple lines, try to stick them all on one expression. the compiler can optimize by modifying the string in place, providing a speed and memory boost. if the statements are split into multiple lines, the Visual Basic compiler will not generate the Microsoft Intermediate Language (MSIL) to allow in-place concatenation. see the StringBuilder example discussed earlier. include Return Statements

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.