. NET Performance Tuning: Introduction to ANTS Performance Profiler

Source: Internet
Author: User

In use. NET, the next problem may be the problem of procedural optimization, and performance optimization sometimes involves all aspects, for example, the host system, database, and network environment of the program. When the program is exceptionally large and complex, performance optimization becomes even more difficult.

This series of articles mainly introduces some. NET performance tuning tools, Web performance optimization rules (such as YSlow) and methods. What I do not want to see before writing is the continuous debate on "which language is good and which language is of high performance" in the garden, it really means that all people should know whether such a debate makes sense. We hope we can discuss the issue from the perspective of actual performance optimization.

Basic use of ANTS Performance Profiler

ANTS Performance Profiler is a powerful Performance tuning product under RedGate. The official product page is here.

Let's take a look at the basic usage of the software.

Use the following code to perform a simple test.

This is a console application. The program is very simple. It first executes 10000 loops, outputs and, and then uses LINQ to find the 1000 value output in the list.
Copy codeThe Code is as follows:
Static void Main ()
{
Var list = new List <int> ();

Var sum = 0;
For (var I = 0; I <10000; I ++)
{
Sum + = I;
List. Add (I );
}
Console. WriteLine (sum );

// Find the value use linq: 1000
Var result = list. Where (p => p. Equals (1000 ));
Foreach (var I in result)
{
Console. WriteLine (I );
}
Console. ReadKey ();
}

After the program is compiled, start ANTS Performance Profiler and the Wizard Page is displayed automatically. on this page, you can see that the software supports Performance monitoring of a variety of. NET programs, such as EXE, web, and Windows Service.

In Memory Mace Counters, you can select multiple Counters as needed, including IO, memory allocation, and processor.

For the test DEMO, select the path of the compiled exe file. Because it was just debug compilation, select the exe in \ bin \ Debug \ in the program folder.

In Profiling Mode, you can select the monitoring level, which is basically the balance between the monitoring information and the speed. By default, you can select "most detailed. OtherDetailsFor settings, see help.Documentation.

Click Start Profiling to Start the program.

View and analyze analysis results

The basic working principle of the software is to put a hook in the. NET compiled IL code to record the time, and then display which part of the code consumes the most energy through an intuitive interface. Therefore, this is the most direct method for Performance Tuning. You can optimize the most time-consuming code segments.

Click Start Profiling to Start the previously compiled program.RunIf it is another interactive program such as winform and web, after the operation is completed, you can select the time period to be viewed in the running timeline at the top with the mouse, generally, a peak occurs in a time period with performance problems. You can select that time period.

After selection, you can immediately see the most time-consuming method in the result window below. For example, the DEMO above, of course, the performance is all consumed by the Main function.

The software provides a variety of metric values to view performance loss, with percentages and multiple time formats. Here "seconds" are selected as the measurement unit.

Then select the function to be viewed, and the strength of the software is displayed.

Click the red line on the right to quickly locate the most energy-consuming code. The deeper the color, the more energy-consuming the code. You can see the row number on the left, the number of times the code is executed (Hit Count), the average execution time, and the total execution time. Of course, you can also see the code for analysis.

As to why the code in the DEMO is so energy-consuming when Console. WriteLine is executed for the first time, I think you should know the answer if you carefully read the first chapter of CLR via C.

You can also click the hierarchy icon to view more intuitive performance loss, as shown below.

Conclusion

ANTS Performance Profiler is the first and most popular tool for Performance Tuning. So I will share it with you in the first article, hoping to help you.

It is very intuitive and powerful, because complicated projects at hand are not suitable for DEMO, so I just wrote a simple code for demonstration, the power of it also needs to be well understood when you really encounter performance problems using it.

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.