This post originated from an RSS feed registered with .NET Buzz
by Scott Watermasysk.
Original Post: SnippetCompiler + StopWatch = Good
Feed Title: ScottW's ASP.NET WebLog
Feed URL: /error.aspx?aspxerrorpath=/blog/rss.aspx
Feed Description: ASP.NET and Blogging
I am really liking Jeff Key'sSnippetCompiler. Its not "official" testing, but I like doing quick timing tests with it. Since these tests are small, its important to have an accurate time interval. In the past if have used Mentalis.org'sStopWatch class.
The .NET framework provides several ways to measure time intervals; you can use the DateTime.Now property or the Environment.TickCount property. However, these methods are not very precise. In fact, the Environment.TickCount can have a worst case resolution of 500 milliseconds. If you need to measure short time intervals, these methods may not be good options.[Mentalis.org]
So I quickly whipped up a snippet template which also contains a comment free version of the the StopWatch class. You can grab it here, if you are interested. Just remove the .txt and drop it in the template folder.
To use: StopWatch sw = new StopWatch(); //Run your test sw.Write(”My test took:”);