C++ : clock_t clock(void) , CLOCKS_PER_SEC
This function returns number of clock ticks elapsed between the start of our program and current execution point.This function is declared inside <time.h>. There is also macroCLOCKS_PER_SEC which defines the number of clock ticks per second. Both are used in the following example to find out the execution time in seconds.
#include <time.h> ErrorCode saveContentsToDisk(string & strContentToSave) { clock_t start = clock(); .... // the colde block we need to inspect .... clock_t elapsedTicks = clock() - start; double elapsedTimeInSeconds = elapsedTicks/CLOCK_PER_SEC }
Windows : GetLocalTime(), GetSystemTime()
#include <windows.h> ErrorCode saveContentsToDisk(string & strContentToSave) { SYSTEMTIME startTime,endTime; GetLocalTime(&startTime); .... // the colde block we need to inspect .... GetLocalTime(&endTime); WORD elapsedTimeInSeconds=endTime.wSecond - startTime.wSecond; WORD elapsedTimeInMilliSeconds = endTime.wMillisecond-startTime.wMillisecond; }
To know more about GetLocalTime: http://msdn.microsoft.com/en-us/library/ms724338(VS.85).aspx