Chapter 9. Analyzing Code Performance

In this chapter, we will have an overview of performance analysis and software testing techniques. When trying to get the best out of our code, nothing is more useful than profiling our work. Profiling means analyzing code performance results, routine by routine, trying to find bottlenecks, which gives us the ability to identify performance consumption patterns.

Another important aspect of the software development lifecycle is testing our application. In this chapter we will see various kinds of tests and features, as offered by the Visual Studio test engine (MsTest). Tests are useful to analyze how our application behaves regarding performance, may help with trying to simulate the end-user feeling, or may help with analyzing the reliability of our application, or its ability to scale out.

We will cover the following pointers in this chapter:

  • Software profiling
  • Profiling with Visual Studio 2013
  • Testing with Visual Studio 2013
  • Static program analysis

Software profiling

Testing application results against the main performance aspects such as resource usage, latency, throughput, availability, scalability and efficiency is definitely the way any performance engineering fulfills its goals by comparing such results to the desired performance levels.

As developers, we need a numerical expression of all performance aspects to infer if something is working incorrectly, or simply if some optimization may improve a performance aspect. Never consider simply aggregated values. Always go deep in the performance analysis of any software. This is the key to success to developing a performing application.

Profiling is the technique used to analyze at runtime how our software behaves regarding resource usage (CPU or memory consumption), with details aggregated per routine/function. This means that a profiling engine will explicitly inform you which routine is consuming the most CPU time in our application, which is a huge help in bottleneck identification.

Obviously, a profiling tool is not mandatory. For instance, we could use our instincts to deduce that if a web application is taking lot of time to respond, maybe the database behind is slow to respond, or is receiving bad performing queries, or the web application is wasting time in doing its job. Although using a profiling tool is not mandatory, often we will need to find where a bottleneck is happening. By using a profiling tool, we can find the bottleneck quickly.

Today, any performance analysis tool should give us a detailed report of how our application executes. By using good profiling technology, we should never ask ourselves what the cause of bad performance is because we should already know it. If we have a slow responding web application, by profiling its execution in Visual Studio, we will know exactly which method(s) needs optimization.

Profiling supports different techniques. For instance, an instrumentation profiling injects special instructions in our method body (usually at the beginning and the end). This behavior happens when CLR executes its JIT compiler, so we cannot see such code in our Visual Studio text editor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.219