Hi
I am trying to messure the time it takes for Dijkstras algorithm to calculate a route. I am using clock(); to messure. But I have a few questions about the method....what is ticks and clock ticks per second???
Printable View
Hi
I am trying to messure the time it takes for Dijkstras algorithm to calculate a route. I am using clock(); to messure. But I have a few questions about the method....what is ticks and clock ticks per second???
I'm unfamiliar with clock().
One tick is, i guess one clock cycle. i.e. what the CPU does in one 'tick'. Ticks per second are how many it does in one second (i.e. the speed of your CPU). Not 100% if this is what it means by a 'tick' though.
I'd use the API GetTickCount(), which gives the number of miliseconds passed since startup. So you could call it before and after your function. The difference would be the miliseconds it too to run your function.
thanks ;) But I need the time in microseconds
Why? If the function is done too quickly then why not just run it multiple times and count from that?
GetTickCount is inaccurate. It's especially inaccurate on the 9x series (updating only 13 times a second or so).
clock() is just as inaccurate. You have no guarantee at all about the actual resolution of this call. POSIX demands that CLOCKS_PER_SEC be 1000000, but nothing demands that the status is updated that often. CLK_TCK is equivalent to CLOCKS_PER_SEC, but outdated and considered obsolete.
clock() is also unsafe, because it wraps around a lot. On a POSIX-compliant system with a 32-bit clock_t, it wraps every 72 minutes, which is a lot. Get such a wrap into your measurement period and you get confusing results.
clock() is also unpredictable. OSs differ in what they include in the measurement, e.g. some unices include the processor time of child processes, while others don't.
If you're measuring real time and have no need for portability, I recommend queryPerformanceCounter() on Windows. There's also some calls for getting the actual processor usage that are better than clock().
On Linux, you can use the times() function to get more accurate info about where and how a process spends its time.