Page 1 of 1
					
				ElapsedMilliseconds for C/C++
				Posted: Thu Dec 09, 2010 1:42 am
				by Mistrel
				From what I understand, time() is implementation-specific. So I wrote a replacement using Win32. if anyone has a way of doing this in a standardized way that is more portable, I'm all ears.
I programmed this for C++. I'm assuming that it should work fine in C as well.
Code: Select all
INT64 elapsedMilliseconds() {
   SYSTEMTIME sysTime;
   FILETIME elapsed;
   INT64 posix;
   
   GetSystemTime(&sysTime);
   SystemTimeToFileTime(&sysTime, &elapsed);
   
   // FILETIME to POSIX
   posix = *(INT64*)&elapsed;
   
   posix = (posix - 116444736000000000) / 10000;
   
   return posix;
}
 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Thu Dec 09, 2010 1:55 am
				by freak
				I moved this to OffTopic. The Tips section is for PureBasic codes.
			 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Thu Dec 09, 2010 2:12 pm
				by Joakim Christiansen
				Helping Kwaï chang caïne or something? 

 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Thu Dec 09, 2010 11:16 pm
				by idle
				was there some problem with using GetTickCount_() ?
			 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Fri Dec 10, 2010 5:01 am
				by Nituvious
				idle wrote:was there some problem with using GetTickCount_() ?
He may have wanted a cross platform function.
 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Fri Dec 10, 2010 3:32 pm
				by DarkDragon
				Nituvious wrote:idle wrote:was there some problem with using GetTickCount_() ?
He may have wanted a cross platform function.
 
Euh.. but GetSystemTime and SystemTimeToFileTime are more WinAPI functions than one GetTickCount or timeGetTime.
 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Fri Dec 10, 2010 8:46 pm
				by idle
				I was just wondering if there was a difference with GetTickCount_() on 64 bit systems
			 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Sat Dec 11, 2010 12:13 am
				by Mistrel
				GetTickCount_() has a 49 day resolution.
			 
			
					
				Re: ElapsedMilliseconds for C/C++
				Posted: Sat Dec 11, 2010 12:59 am
				by Rescator
				idle wrote:I was just wondering if there was a difference with GetTickCount_() on 64 bit systems
Nope, which is why you should use 
GetTickCount64 it's only Windows 6.x or later but it gives you like hundreds of years before it wraps?