   Timing information in C++
  I'm trying to profile various parts of my application 'by hand', and finding that the standard ctime header doesn't really give me the accuracy I want. Is there an easy way to do this? I don't need anything earth-shaking, milliseconds will do.   
  Have you tried TimeGetTime() ? GetTickCount() ? (assuming you're working on a win32 platform)They both give you something like the number of milliseconds ellapsed since your computer boot up.Regardsjanta   ;  Keep in mind that those will not be very accurate milliseconds though.. sometimes querying timeGetTime ( "TimeGetTime" will not work, pay attention to the capitalisation ) twice with a short delay such as 5 or 10 milliseconds will return you the exact same time.If you want something really accurate (Windows only) have a look at "QueryPerformanceFrequency" and "QueryPerformanceCounter". Not very hard to use, there's a lot of tutorials on the net which wraps you all that around one or two simple functions and you're good to go with real accuracy [smile]Try this maybe:#include <windows.h>__int64 TimeFrequency;double TimeBegin;void InitTimer(){  __int64 time;  QueryPerformanceFrequency((LARGE_INTEGER*)&TimeFrequency);  QueryPerformanceCounter((LARGE_INTEGER*)&time);  TimeBegin = (double)time / TimeFrequency;}double CurrentTime(){  __int64 time;  QueryPerformanceCounter((LARGE_INTEGER*)&time);  return ((double)time / TimeFrequency) - TimeBegin;}Calling for CurrentTime() will return, as a 'double', the elapsed time in seconds since you first called InitTimer() at the beginning of your program. You can see it's not really complicated too so you can modify it as you need, to simply support milliseconds in integer format if you like. (But now the milliseconds would be a lot more precise).   ;  right, timeGetTime() ! I always spell that one wrong :)If you are *really* concerned by accuracy (it seems like th OP isn,t, actually) you should remember to call QueryPerformanceCounter every once in a while since the return value may vary depending on several factor like the heat of the CPU for example.Also, if your machine has multicore CPU or multiples CPU, QPC/QPF may give you headaches if not used properly.Cheers !   ;Quote:Original post by Hedos[...]If you want something really accurate (Windows only) have a look at "QueryPerformanceFrequency" and "QueryPerformanceCounter". Not very hard to use, there's a lot of tutorials on the net which wraps you all that around one or two simple functions and you're good to go with real accuracy [smile][...]Be aware that QueryPerformanceCounter is not dual-core friendly without quite a bit of effort.Use timeBeginPeriod with timeGetTime for ~1ms accuracy   ;Quote:Original post by ExtrariusUse timeBeginPeriod with timeGetTime for ~1ms accuracytimeBeginPeriod(1) that is ;)And call timeEndPeriod(1) in termination of the program to ensure Windows standard timing frequencies hereafter.   ;  Ah, it's a Linux box, actually. This is for work, not a game. But thanks. :)   ;gettimeofday() should be found on most POSIX-compliant systems. Another option is clock_gettime(), which in theory has nanosecond precision.   ;  http://www.linuxquestions.org/questions/showthread.php?t=414789&highlight=windows+timer   ;  Thank you, gettimeofday was just what I needed. :)   