Sep 12
Lightning Quick .NET Profiling
Here’s a super-quick tip for evaluating the time-hit of a section of .NET code.
You’ll obviously want to use profiling tools once your application has taken shape, but I’ve been in the situation many times where you want to quickly evaluate several code options.
Simply use the System.Diagnostics.Stopwatch class to record the time taken for a piece of code to execute:
System.Diagnostics.Stopwatch theWatch = new System.Diagnostics.Stopwatch();
theWatch.Start();
// Execute a block of code..
theWatch.Stop();
Response.Write(theWatch.ElapsedMilliseconds.ToString());