Hernan de Lahitte's blog
.NET Development from the trenches
Sign in
|
Join
Home
Contact
About
RSS
Atom
Comments RSS
Search
Tags
.NET General
Architecture
EDRA (Shadowfax)
Forms Authentication
GAT
MBI 3
Patterns & Practices
Security
Web Services
WSSF
News
Visit these related links:
Digit Factory S.R.L.
Patterns & Practices
Web Service Software Factory: Modeling Edition
ESB Guidance
Navigation
Home
Blogs
Archives
October 2011 (1)
June 2011 (2)
April 2011 (1)
March 2011 (3)
November 2010 (1)
October 2010 (1)
June 2010 (1)
May 2010 (3)
April 2010 (1)
December 2009 (1)
September 2009 (1)
July 2009 (2)
June 2009 (4)
May 2009 (2)
April 2009 (7)
December 2008 (1)
November 2008 (1)
September 2008 (1)
July 2008 (1)
June 2008 (2)
March 2008 (1)
January 2007 (1)
November 2006 (1)
October 2006 (1)
May 2006 (1)
December 2005 (2)
November 2005 (2)
September 2005 (1)
August 2005 (1)
June 2005 (2)
May 2005 (3)
March 2005 (1)
February 2005 (1)
January 2005 (1)
December 2004 (1)
November 2004 (2)
October 2004 (1)
September 2004 (1)
August 2004 (3)
July 2004 (4)
June 2004 (6)
May 2004 (3)
April 2004 (4)
March 2004 (8)
February 2004 (3)
Books
Writing Secure Code, Second Edition
.NET Framework Security
Security Engineering...
Newsgroups
About .NET security.
ASP.NET security.
Others
Disclaimer
Author Bio
Security
Security Developer Center
Building Secure ASP.NET Applications
Threats and Countermeasures
.NET Framework Security
Writing Secure Code
Keith Brown's web site
NCrypto project
Security Tools
Timing Managed Code
As part of the samples included in my last presentation about .NET Performance and Scalability, there is a useful class that encapsulates the Win32 functions
QueryPerformanceCounter
and
QueryPerformanceFrequency
. These functions let you measure the performance of your code to nanosecond accuracy (10
-9
sec). However, after all internal and
interop
cross-boundary calls, you get 10 us (10
-6
sec) that is an order of magnitude better that the 10 milliseconds resolution of the managed DateTime class.
Note
: This class (Stopwatch) resembles (same interface definition) the one in the .NET Framework 2.0 (Whidbey) that you will found on the System.Diagnostics namesapece. The good thing is that you can use this class with .NET Framework v1.1 and you will have full compatibility when v2.0 comes up.
Downloads
You can download the code from
here
.
Usage
Its usage is very straightforward.
Stopwatch myTimer =
new
Stopwatch();
myTimer.Start();
// Do some stuff here
myTimer.Stop();
// Show Results
double
result = myTimer.Elapsed.TotalMilliseconds;
Console.WriteLine( "Elapsed milliseconds: {0}", result );
// If you want a new timing, just reset the current timer
myTimer.Reset();
Enjoy it!
Published Friday, June 25, 2004 5:23 PM by
HernanDL
Filed under:
.NET General
Comments
No Comments
Leave a Comment
Title
(required)
Name
(required)
Your URL
(optional)
Comments
(required)
Remember Me?