How to implement hardware timer on OS Windows. I need to measure computations in milliseconds and nanoseconds.
for (i=0;i<1024;i++){
//start timer
//computations
//end timer
//printf result(end - start)
}
How to implement hardware timer on OS Windows. I need to measure computations in milliseconds and nanoseconds.
for (i=0;i<1024;i++){
//start timer
//computations
//end timer
//printf result(end - start)
}
Try using QueryPerformanceFrequency and QueryPerformanceCounter methods to obtain time in sub millisecond resolution:
LARGE_INTEGER cpu_khz, start_time, end_time;
QueryPerformanceFrequency(&cpu_khz);
for (i=0;i<1024;i++) {
QueryPerformanceCounter(&start_time);
// computations
QueryPerformanceCounter(&end_time);
double delta_time = (start_time.QuadPart-end_time.QuadPart) / (double)cpu_khz.QuadPart;
printf("took %.3f seconds", delta_time);
}