By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,899 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,899 IT Pros & Developers. It's quick & easy.

time measures better resolution

P: n/a
Hello,

I would like to measure the time taken by a method to run for performance
tests.

I use the class DateTime and TimeSpan like this:

start = DateTime.Now;
....method execution
ts = DateTime.Now.Substract(start);

ts is of type TimeSpan. I can get the time using
ts.TotalMilisecond;
However the measures are not precise as the resolution, refering to the .NET
doc, is:

System Approximate Resolution
Windows NT 3.5 and later 10 milliseconds
Windows NT 3.1 16 milliseconds
Windows 98 55 milliseconds
Is it possible to have better resolutions, like 1 millisecond (I have
Windows 2000)?

Thanks
Valéry
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You can try the PerformanceCounter class:

http://msdn.microsoft.com/library/de...classtopic.asp
Or you can use interop to call QueryPerformanceCounter:
(there are some articles about this on codeproject, but I'm unable to access
that site right now. Try searching there)

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]
private static extern bool QueryPerformanceCounter( ref long
lpPerformanceCount);

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]
private static extern bool QueryPerformanceFrequency( ref long
lpFrequency);


"Valéry Bezençon" <va*************@epfl.ch> wrote in message
news:40********@epflnews.epfl.ch...
Hello,

I would like to measure the time taken by a method to run for performance
tests.

I use the class DateTime and TimeSpan like this:

start = DateTime.Now;
...method execution
ts = DateTime.Now.Substract(start);

ts is of type TimeSpan. I can get the time using
ts.TotalMilisecond;
However the measures are not precise as the resolution, refering to the ..NET doc, is:

System Approximate Resolution
Windows NT 3.5 and later 10 milliseconds
Windows NT 3.1 16 milliseconds
Windows 98 55 milliseconds
Is it possible to have better resolutions, like 1 millisecond (I have
Windows 2000)?

Thanks
Valéry

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.