How to test functions speed in Visual Studio
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.
In Visual Studio 2013
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 Visual Studio 2017
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 Visual Studio 2019
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.
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.