Table of Contents
.NET Performance Tuning Series Articles
Basic use of ANTS Performance Profiler
Viewing and analysis of analysis results
Conclusion
Home Backend Development C#.Net Tutorial ANTS Performance Profiler (.NET performance tuning tutorial)

ANTS Performance Profiler (.NET performance tuning tutorial)

Apr 25, 2017 am 10:57 AM
c#


.NET Performance Tuning Series Articles

Series Article Index

  • One of .NET Performance Tuning: ANTS Use of Performance Profiler

  • #.NET performance tuning part 2: using Visual Studio for code measurement

  • .NET performance tuning Part 3: Tuning tools and methods for YSlow related rules

Using .NET After you quickly get started and develop an application, the next problem you face may be program performance tuning. Performance tuning sometimes involves various aspects, such as program hosting system, database, network environment, etc., and When the program is extremely large and complex, performance tuning will become even more difficult to start.

This series of articles will mainly introduce some .NET performance tuning tools, Web performance optimization rules (such as YSlow) and methods, etc. The last thing I want to see before it is written is the endless debate in the garden about "which language is better and which language has higher performance". Without further ado, anyone who really understands should know whether such a debate is meaningful. I hope we can start from the practical point of view. Discuss the problem from the perspective of performance optimization.

Basic use of ANTS Performance Profiler

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

Let’s first look at the basic use of the software.

Use the following code for a simple test.

This is a console application. The program is very simple. First loop 10,000 times, output the sum, and then use LINQ to find the value of 1000 in the list and output it.

1 static void Main() 2 { 3     var list = new List<int>(); 4  5     var sum = 0; 6     for (var i = 0; i < 10000; i++) 7     { 8         sum += i; 9         list.Add(i);10     }11     Console.WriteLine(sum);12 13     //find the value use linq: 100014     var result = list.Where(p => p.Equals(1000));15     foreach (var i in result)16     {17         Console.WriteLine(i);18     }19     Console.ReadKey();20 }
Copy after login

After compiling the program, start ANTS Performance Profiler, and a wizard page will automatically pop up. On this page, you can see that the software supports performance monitoring of a variety of .NET programs, such as EXE, web, Windows Service, etc. .

In Performace Counters, you can choose a variety of counters according to your needs, such as IO, memory allocation, processor, etc.

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

In Profiling Mode, you can select the level of monitoring, which is basically a balance between the amount of monitoring information and the speed. The default selection is "most detailed". For other detailed settings, please refer to the help document.

Click "Start Profiling" to start the program.

Viewing and analysis of analysis results

The basic working principle of the software is to put hooks in the IL code compiled by .NET to record time. Then an intuitive interface shows which parts of the code consume the most energy. So this is the most direct method of performance tuning, just optimize the most time-consuming code segments.

Click "Start Profiling" to start the previously compiled program, and the software will start execution. If it is other interactive programs such as winform, web, etc., after operating the functions that require performance tuning, Just use the mouse to select the time period you want to view in the running timeline at the top. Generally, there will be a peak during the time period when there are performance problems, just select that time period.

After selection, you can immediately see the most time-consuming method in the result window below, such as the DEMO above. Of course, the performance is consumed in the Main function superior.

The software provides a variety of measurement values ​​to view performance losses, including percentages and multiple time formats. Here, "seconds" is selected as the unit of measurement.

# Then select the function you want to view, and the power of the software will become apparent.

  • Click on the red line on the right to quickly locate the most energy-consuming code. The darker the color, the more energy-consuming the code is.

  • On the left you can see the line number, the number of times this code has been executed (Hit Count), the average execution time, the total execution time, and of course you can also see the code for analysis. .

As for why this code in the DEMO consumes so much energy when executing Console.WriteLine for the first time, I think you should be able to know if you read the first chapter of "CLR via C#" carefully. The answer is.

Of course, you can also click on the hierarchy icon to view a more intuitive performance loss, like the following.

Another benefit of such a hierarchical structure diagram is that you can see the internal implementation of the .NET Framework.

When making some decisions, such as whether to use native functions or third-party components, this function will become very useful, because it can more intuitively see where the performance bottlenecks of the internal implementation are.

Conclusion

ANTS Performance Profiler is my first and favorite tool for performance tuning, so I put it in the first article. Let me share it with you, I hope it can be of some help to you.

It is very intuitive and powerful. Because the complex project at hand is not suitable for DEMO, so I just wrote a simple code for demonstration. Its power can only be used when you actually encounter performance problems. It’s time to experience it.

If there are any omissions or additions in the article, please leave a message to discuss together, and please also pay attention to subsequent related articles.

If the article is helpful to you, please recommend it, thank you :)

The above is the detailed content of ANTS Performance Profiler (.NET performance tuning tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
C# Serialization C# Serialization Sep 03, 2024 pm 03:30 PM

Guide to C# Serialization. Here we discuss the introduction, steps of C# serialization object, working, and example respectively.

Active Directory with C# Active Directory with C# Sep 03, 2024 pm 03:33 PM

Guide to Active Directory with C#. Here we discuss the introduction and how Active Directory works in C# along with the syntax and example.

Random Number Generator in C# Random Number Generator in C# Sep 03, 2024 pm 03:34 PM

Guide to Random Number Generator in C#. Here we discuss how Random Number Generator work, concept of pseudo-random and secure numbers.

C# Data Grid View C# Data Grid View Sep 03, 2024 pm 03:32 PM

Guide to C# Data Grid View. Here we discuss the examples of how a data grid view can be loaded and exported from the SQL database or an excel file.

The difference between multithreading and asynchronous c# The difference between multithreading and asynchronous c# Apr 03, 2025 pm 02:57 PM

The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

Factorial in C# Factorial in C# Sep 03, 2024 pm 03:34 PM

Guide to Factorial in C#. Here we discuss the introduction to factorial in c# along with different examples and code implementation.

Patterns in C# Patterns in C# Sep 03, 2024 pm 03:33 PM

Guide to Patterns in C#. Here we discuss the introduction and top 3 types of Patterns in C# along with its examples and code implementation.

Prime Numbers in C# Prime Numbers in C# Sep 03, 2024 pm 03:35 PM

Guide to Prime Numbers in C#. Here we discuss the introduction and examples of prime numbers in c# along with code implementation.

See all articles