. NET performance optimization 2: Use Visual Studio for code measurement

Source: Internet
Author: User
Tags visual studio 2010
. Net Performance Tuning Series Article

Index of series articles

    • . Net Performance Tuning: Use of ants performance profiler
    • . NET performance optimization 2: Use Visual Studio for code measurement
    • . Net Performance Tuning 3: tuning tools and methods for yslow-related rules
Use Visual Studio Code Measurement

In this article, code, database, and network optimization are aside for the time being. From the perspective of software code measurement, we can look at its role in. NET performance tuning.

When a software project is exceptionally large, it is unrealistic to evaluate the software complexity and reliability by using a simple codereview. Fortunately, software can accomplish these tasks. Reducing the complexity of the software will also greatly help performance tuning.

Before Visual Studio 2008, some third-party tools should be used for code measurement, such as devmetrics and C # source code metrics, microsoft integrated the code measurement tool from Visual Studio 2008.

Click the "analysis" menu of Visual Studio to see that the measurement tool can perform code measurement for the current project or the entire solution.

The drop-down menu also contains a code performance analysis tool similar to the ants performance profiler described in the first article. After simple use, you can find that you need to view the tool. net Framework is invisible for energy consumption, and other functions can basically meet the needs. Thanks to the reminder from Yuanyuan Fengyun.

After a short run, you can see the analysis results.

All columns that can be computed are listed here. The following describes the meaning of the calculated result values by msdn.

    1. hierarchy: the hierarchy is subdivided by project-namespace-class-attribute/method, therefore, you can view the relevant code measurement values for only one method.
    2. Maintainability Index: calculates an integer between 0 and 100, indicating the relative ease of code maintenance. A larger value indicates better maintainability. The color icon level can be used to quickly identify fault points in the code. The green level is between 20 and 100, indicating that the Code has good maintainability. The yellow level is between 10 and 19, indicating moderate maintainability of the Code. The red level is between 0 and 9, indicating low maintainability.
    3. circle complexity: describes the complexity of the code structure. Created by calculating the number of different code paths in the Program stream. Programs with complex control flows require more tests to achieve good code coverage and are not easy to maintain. In some cases, the computation of the method in Visual Studio 2010 is different from that in earlier versions. For details, see Visual Studio 2010's changes in Code complexity computing.
    4. inheritance depth: specifies the number of class definitions extended to the root of the class hierarchy. The deeper the hierarchy, the harder it is to understand where the specific methods and fields are defined or/and redefined.
    5. class coupling: it is measured by parameters, local variables, return types, method calls, generic or template instantiation, base classes, interface implementations, fields defined on external types, and feature modification. the degree of coupling with the unique class. Good software design requires high cohesion and low coupling between types and methods. High coupling indicates that the design is difficult to reuse and maintain because it has many dependencies with other types.
    6. Number of lines in the Code: indicates the approximate number of lines in the code. The count is based on the Il code, so it is not the exact number of lines in the Source Code file. A high count may indicate that a type or method is trying to execute too much work and should be split. It may also indicate that this type or method is difficult to maintain.

The two most important metric values are the circle complexity and class coupling, so that the Program maintains a high class clustering and low coupling. If the circle complexity is too high, the function should be disassembled, in this way, performance optimization can be broken one by one, making maintenance easier.

Conclusion

It is hoped that the complexity and maintainability of the software will be reduced first when the program performance optimization is discussed, so that the idea can be clear enough in case of complicated performance optimization problems, you can focus on the segmented code segments, rather than interfering with logic sorting and thinking with too much code noise.

So this series of articles first took this part of content to the second article to discuss with you.

The article has some omissions and needs to be supplemented. Please leave a message to discuss them together, and pay attention to the subsequent articles.

If the article is helpful to you, please recommend it. Thank you.

Related Article

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.