I\'m trying to measure some activity in C (Matrix multiplying) and noticed that I should do something like this:
clock_t start = clock();
sleep(3);
clock_t e
If you don't care about being tied to Windows, you can try the high resolution timer. It's is a lot more precise than time(), which only has a precision of a single second because it the uses UNIX format.
#include
#include
__int64 countspersec = 0;
double secpercount = 0.0;
__int64 starttime = 0;
__int64 curtime = 0;
int main() {
// Get current time, and determine how fast the clock ticks
QueryPerformanceCounter((LARGE_INTEGER*)&starttime);
QueryPerformanceFrequency((LARGE_INTEGER*)&countspersec);
secpercount = 1.0/(double)countspersec;
/* calculate something */
// Standard end-start stuff, account for clock speed
QueryPerformanceCounter((LARGE_INTEGER*)&curtime);
std::cout << "Time needed: " << (curtime-starttime)*secpercount << " sec\n";
return 0;
}