Share via


Visual Studio Performance Analysis

  Visual Studio is a massive IDE which holds many of the features.

You have met with a lot of them in your development evolution like compiling, debugging and others.

In this article you will learn how to use Performance Analysis tool in your Visual Studio.

What is Performance Analysis?

I'm sure that you have at least once ask yourself how to see the performance of your application, so you can know which part are needed to be changed.

There are a lot of ways to accomplish that. On of that way is to use Performance Analysis.

With that tool you can see how many percentage of CPU using is some algorithm using. Also you can see what is on the top of the stack and what is on the bottom of the stack.

How to use Performance Analysis?

To use Performance Analysis in Visual Studio is very easy. First, open a new project (it's not important which language and which template you are using: Console Application, Windows Forms Application, Windows Presentation Foundation,...).

You will have to write some code in order to make a sense to run a Performance Analysis. After you write some code, click on the "ANALYZE" in the Visual Studio and click "Start Performance Analysis".

When you are runing Performance Analysis for the first time, it may seems to run slow, but that's ok.

Also if you are using some Antivirus application, your Antivirus application may first analyze if your application is malicious and during that time, your application will be runned in the Sandbox mode. After that analysis just click "Continue execution" and your application will run normally. 

You may notice that Visual Studio have started to generate some output notes in the "Output" section. 

In the moment when you have started your analysis, you will see something like this:

http://i.imgur.com/kyyHCZz.png

Also you can notice some text in the "Output" section:

http://i.imgur.com/YkLoJCv.png

That's a good sign. It means that everything is working ok for now. 

Now you can work what you want in your application and when you finish with that work, you can close your application.

When your application is closed, Performance Analysis will generete the results for you.

You will see graphicon which is telling you which part of your code is taking the most percentage of the CPU.

http://i.imgur.com/fEGgAFA.png

Based on graphicon, you can see at the 2 seconds that the application have used some percentage of the CPU. In this example it is very small percentage, because I have used small XML file to show it's values in the DataGridView control, but if I have used a bigger file instead of that small, that percentage would be larger.

After all of that look at the "Hot Path" part. There you can see the name of the functions in your applications (methods, event handlers,...) and see how many percentages of the CPU is each function using. 

Also you can click on some function, let's say "WindowsFormsApplication7.Program.Main" and you will see this:

http://i.imgur.com/GAkKpWo.png 

Now you can see what is on the top of the stack and what is on the bottom of the stack.

Those are the primary functions in Performance Analysis. For more check on the MSDN.