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

Started by
4 comments, last by SnprBoB86 17 years, 8 months ago
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
Advertisement
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.
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 ?
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.
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 ^^
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;}

This topic is closed to new replies.

Advertisement