Sign in to follow this  
tlc660

[C#] System.Diagnostics.Stopwatch And Environment.TickCount

Recommended Posts

tlc660    122
which are better performance and suggested to use for Game timing render Loop? me knew the QueryPerformanceCounter are the best solution, but me try to do all in pure managed. thank you very much

Share this post


Link to post
Share on other sites
Limitz    342
MSDN says that if available the StopWatch class will use the underlaying performance timer, so this is probably the way to go. But you should take into account that even though you may be doing all managed underlaying function in .NET may not.

Greetings.

Share this post


Link to post
Share on other sites
tlc660    122
thanks Limitz
but me was sorry that me poor with english, cant understand well what you are trying to tell me.

did you mean the StopWatch actually are low level wrapper which call to something like QueryPerformanceCounter ?
also mean that StopWatch are better performance ?

Share this post


Link to post
Share on other sites
Limitz    342
Yes, Stopwatch will use the performance timer if it is there. I think it will be better than TickCount.

Also, some managed functions you use are wrappers for unmanaged code, so not using unmanaged code for this reason is not always the better solution.

Hope that will help you.
Greetings.

Share this post


Link to post
Share on other sites
tlc660    122
thanks your advice,
me try to do all in managed because me are unfamiliar with those things(dll, com...),
so better me do in all "managed", so that me can manage and read my code easier ^^

Stopwatch is great enough for me ^^

Share this post


Link to post
Share on other sites
SnprBoB86    277
Decompiled with Reflector


static Stopwatch()
{
if (!SafeNativeMethods.QueryPerformanceFrequency(out Stopwatch.Frequency))
{
Stopwatch.IsHighResolution = false;
Stopwatch.Frequency = 0x989680;
Stopwatch.tickFrequency = 1;
}
else
{
Stopwatch.IsHighResolution = true;
Stopwatch.tickFrequency = 10000000;
Stopwatch.tickFrequency /= (double) Stopwatch.Frequency;
}
}




public static long GetTimestamp()
{
if (Stopwatch.IsHighResolution)
{
long num1 = 0;
SafeNativeMethods.QueryPerformanceCounter(out num1);
return num1;
}
return DateTime.UtcNow.Ticks;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this