In use. NET to start and develop the application quickly, the next problem may be the performance tuning aspects of the program, and performance tuning can sometimes involve all aspects of the problem, such as the program host system, database, network environment, and so on, and when the program is unusually large and complex, performance tuning will become even more impossible.
This series of articles will mainly introduce some. NET performance tuning tools, Web performance optimization rules (such as YSlow) and methods, and so on. The most do not want to see before the paper is the garden uninterrupted "which language is good, which language performance high" debate, not to say, the real sensible understand all should know that this debate has no meaning, I hope we can from the actual performance optimization perspective to discuss the problem.
Basic use of ANTS performance Profiler
ANTS Performance Profiler is the Redgate's powerful performance tuning product, the official product page is here.
Let's take a look at the basics of software use.
Use the following code to do a simple test.
This is a console application, the program is very simple, first 10,000 cycles, output and, and then use LINQ in the list to find 1000 of the value output.
Copy Code code 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 compiling the program, start ants Performance Profiler, will automatically eject the wizard page, this page, you can see the software support a variety of. NET program performance monitoring, such as EXE, Web, Windows service, and so on.
In performace counters, you can select a variety of counters, IO, memory allocations, processors, and so on as needed.
For test demo, select the compiled exe file path, because just Debug compiled, so select the program folder \bin\debug\ inside the EXE can.
In profiling mode, you can choose the level of monitoring, the basic is to monitor the amount of information and speed of the tradeoff, the default choice of "most detailed" can be. Additional detailed settings refer to the Help documentation.
Click "Start Profiling" to start the program.
View and analysis of analysis results
The basic working principle of the software is in. NET compiled IL code into the hook to record the time, and then through the intuitive interface to show which part of the code consumes the most. So this is the most straightforward approach to performance tuning, which is optimized for the most time-consuming code segments.
Click "Start Profiling" after the start of the compiled program, the software began to execute, if it is other interactive programs such as WinForm, Web, etc., the operation needs to perform performance tuning function, at the top of the running time axis with the mouse to select the time to see the period can be, Generally have a performance problem of the time period will appear a crest, select that time period can be.
When selected, you can immediately see the most time-consuming method in the results window below, such as the demo above, and of course the performance is consumed in the main function.
The software provides a variety of measures to view performance losses, percentages and multiple time formats, where "seconds" is selected as the unit of measure.
Then select the function you want to view, and the software's strength is revealed.
On the right side of the red line, click to quickly navigate to the most energy-consuming code, the deeper the color means that the more energy consumption of the code. The line number is visible on the left, the number of times the code executes (Hit Count), the average execution time, the total execution time, and, of course, the code to be used for analysis.
As for this code in the demo why the first execution Console.WriteLine so energy-consuming, I think if you take a serious look at the "CLR via C #" Chapter one should be able to know the answer.
Of course you can also click on the hierarchy icon to see more intuitive performance loss, just like the following.
Conclusion
ANTS Performance Profiler is my performance tuning when the first use is also the most like to use the tool, so put in the first article to share to everyone, I hope to bring you some help.
It is very intuitive, powerful, because the complexity of the project at hand does not fit to do demo, so just write a simple piece of code for demonstration, it's the strong place you really encounter performance problems when you use it to feel good.
Articles have omissions and to add, please leave a message to discuss, please also pay attention to the follow-up related articles.
If the article to you a little help, recommend it, thank you:)