Reputation: 635
I would like to test how fast does my projects function work. It would be great if there were a possibility to mark slow places of my function as well so I can change my code to increase performance. I'm using Microsoft Visual Studio 2012 and I know that there is a build-in testing tool but I don't really know where to find it and probably how to use it as well. It would be great if someone could help me with this issue.
Upvotes: 47
Views: 127952
Reputation: 13182
Visual Studio shows execution time in milliseconds for each line or when Run To Click is used during debugging session, which can give some rough idea of the statement execution time:
For simple measurements Stopwatch class can be a handy option too.
For more advanced scenarios there is a built-in profiler in Visual Studio Analyze CPU usage without debugging in the Performance Profiler.
And for precise performance measurements there is an excellent and powerful tool BenchmarkDotNet.
Upvotes: 66
Reputation: 1136
In the top menu, go to ANALYZE
-> Performance and Diagnostics
Check the Performance Wizard to calculate time required. Click- Start. Now select - Instrumentation to measure Function calls and count. Click next. Select- One or more available projects in that name of your project will be shown. Click next. Again click next. Check- Launch profiling after the wizard finishes. Now Click Finish button.
In the top menu, go to ANALYZE
-> Performance Profiler
Check the Performance Wizard to calculate time required. Click- Start. Now select - Instrumentation to measure Function calls and count. Click next. Select- One or more available projects in that name of your project will be shown. Click next. Again click next. Check- Launch profiling after the wizard finishes. Now Click Finish button.
However, you may also prefer to use the Visual Studio Command Window and VSPerfCmd to do your profiling, as it has features the Performance Profiler does not. See: https://msdn.microsoft.com/en-us/library/dd255376.aspx
If you run into problems using Performance Wizard on Windows 10, please see: CPU sampling method is disabled in performance profiler.
In the menu bar, go to ANALYZE
-> Performance Profiler
(it is same as VS2017) or simply press Alt+F12
Change target if you want from Change Target Dropdown, it allows to analyze Visual studio projects as well currently executed process, installed executable files ASP.NET application from IIS or currently running application.
Upvotes: 33
Reputation: 3915
Visual Studio contains a lot of good built-in tools for profiling, and many others are available as plugins (also free).
http://msdn.microsoft.com/en-us/library/ms182372.aspx This MSDN resource could be a good starting point.
Upvotes: 4
Reputation: 35805
You find the Performance Wizard in the Analyze menu, if you have a sufficiently good version of Visual Studio (Professional?).
It measures the time spend in each method that is used and the statistics give you a good overview over possible bottlenecks.
Upvotes: 4