Timing The Execution Time Of Your MVC Actions
I recently had the need to find out how much time elapsed during the execution of just my action, so I created a handy little action filter based on System.Diagnostics.Stopwatch. This action filter adds the elapsed time to an HTTP header, appropriately named, X-Stopwatch. I choose to use a header instead of a response in the content body, so that it could be used both with non-HTML responses (binary, JSON, XML, etc) and HTML response. I was amazed at the usefulness of this simple piece of code, because it instantly gave me insight in to the actual execution time of my action to see if my optimizations were having any effect. It allowed me to monitor the execution time of code that I can specifically and easily control the performance of. ...