The in-built Visual Studio’s Profiler can quickly detect performance bottlenecks. To get started with Profiler, you would need Visual Studio Ultimate or Premium version. It’s located under VS top menu -> Analyze->Launch Performance Wizard. In step1, choose “Instrumentation” then follow subsequent steps till finish.
Few basic definitions, better be familiar with.
Elapsed Inclusive Time = Time spent on this current function and children (ms)
Elapsed Exclusive time = Time spent on this current function (ms)
App Inclusive time = Processing time on this current function and children without wait time for IO or other threads.
Here’s the basic summary view after code profiling is completed on my simplified example page.
Notice the section “Functions with most individual work”. At the top is the most expensive function. Click on that and it will lead you to this view.
Most of the time, “Elapsed Exclusive time” along with Caller/Callee view can detect the biggest hurdle in minutes.
Elapsed Exclusive time is basically the time took to execute only those lines of code in that function without any external I/O or wait.
So if I go to the most nested function in any costly execution chain, costly in terms of time/resources, I already know the major hurdle.
This view basically tells all —
1) How much time was spent on that particular function
2) Which all functions called that function and how many times each?
3) This function called which all functions and their respective time.
Another view which I found very helpfull is functions.
This view lists all functions with the various amount of time each one took.
This tool just helps in detecting the most performance-expensive piece of code. We need to go back and fix the code and again run profiler to see the relative performance-gain.
The profiling results can be compared, filtered, exported to a csv/excel file. The profiler can be paused/resume to profile only the affected chain of logic.
Enjoy profiling. Thanks for reading.